summaryrefslogtreecommitdiffstats
path: root/pokemodr/PokeModrUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-05-21 04:55:22 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-05-21 04:55:22 +0000
commit66bb55e0feab92784209bdcf1b2ce5387a83100e (patch)
treea974b25d02581a31b5a4119668585f4ce6a15ba5 /pokemodr/PokeModrUI.cpp
parent820bc54980b906042c0b5231147caea2059af7c9 (diff)
downloadsigen-66bb55e0feab92784209bdcf1b2ce5387a83100e.tar.gz
sigen-66bb55e0feab92784209bdcf1b2ce5387a83100e.tar.xz
sigen-66bb55e0feab92784209bdcf1b2ce5387a83100e.zip
[FIX] Opening files and saving now works
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@159 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/PokeModrUI.cpp')
-rw-r--r--pokemodr/PokeModrUI.cpp77
1 files changed, 58 insertions, 19 deletions
diff --git a/pokemodr/PokeModrUI.cpp b/pokemodr/PokeModrUI.cpp
index 3f103fa0..6db54597 100644
--- a/pokemodr/PokeModrUI.cpp
+++ b/pokemodr/PokeModrUI.cpp
@@ -41,6 +41,7 @@
#include <KRecentFilesAction>
#include <KStandardAction>
#include <KStandardDirs>
+#include <KTemporaryFile>
#include <KToolBar>
#include <KUrl>
#include <KIO/NetAccess>
@@ -113,6 +114,8 @@ PokeModrUI::PokeModrUI(KConfigGroup config, KConfigGroup history, QWidget* paren
toolbar->addAction(KStandardAction::quit(this, SLOT(quit()), toolbar));
addToolBar(toolbar);
splitter->setSizes(QList<int>() << config.readEntry("treeWidth", 100) << config.readEntry("panelWidth", 100));
+ treePokemod->setModel(new PokemodTreeModel(treePokemod));
+ connect(buttonApply, SIGNAL(clicked()), this, SLOT(update()));
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
if (args)
{
@@ -126,8 +129,6 @@ PokeModrUI::PokeModrUI(KConfigGroup config, KConfigGroup history, QWidget* paren
openPokemod(m_recent->urls().at(i));
}
setAutoSaveSettings("MainWindow", true);
- treePokemod->setModel(new PokemodTreeModel(QStringList(), treePokemod));
- connect(buttonApply, SIGNAL(clicked()), this, SLOT(update()));
}
PokeModrUI::~PokeModrUI()
@@ -159,36 +160,37 @@ void PokeModrUI::newPokemod()
void PokeModrUI::openPokemod()
{
- QString path(KFileDialog::getOpenFileName(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMod files"), this));
- if (!path.isEmpty())
+ KUrl::List urls(KFileDialog::getOpenUrls(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMod files"), this));
+ foreach (KUrl url, urls)
{
- if (openPokemod(path))
+ if (!url.isEmpty())
{
- m_recent->addUrl(path);
- m_recent->saveEntries(m_config);
+ if (openPokemod(url))
+ {
+ m_recent->addUrl(url);
+ m_recent->saveEntries(m_config);
+ }
}
}
}
-void PokeModrUI::openPokemod(const KUrl& path)
+bool PokeModrUI::openPokemod(const KUrl& url)
{
- if (path.isLocalFile())
- openPokemod(path.path());
+ if (url.isLocalFile())
+ return openPokemod(url.path());
else
{
QString temp;
- if (KIO::NetAccess::download(path, temp, this))
+ if (KIO::NetAccess::download(url, temp, this))
{
if (openPokemod(temp))
- {
- m_recent->addUrl(path);
- m_recent->saveEntries(m_config);
- }
+ return true;
KIO::NetAccess::removeTempFile(temp);
}
else
KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error");
}
+ return false;
}
bool PokeModrUI::openPokemod(const QString& path)
@@ -216,16 +218,53 @@ bool PokeModrUI::openPokemod(const QString& path)
void PokeModrUI::savePokemod()
{
- Object* object = static_cast<Object*>(treePokemod->currentIndex().internalPointer());
- treePokemod->savePokemod(static_cast<const Pokemod*>(object->pokemod()));
+ // TODO: safer way of doing this?
+ const Pokemod* pokemod = static_cast<const Pokemod*>(static_cast<Object*>(treePokemod->currentIndex().internalPointer())->pokemod());
+ KUrl url = treePokemod->url(pokemod);
+ if (url.isEmpty())
+ saveAsPokemod();
+ else
+ savePokemod(url);
}
void PokeModrUI::saveAsPokemod()
{
- Object* object = static_cast<Object*>(treePokemod->currentIndex().internalPointer());
+ // TODO: safer way of doing this?
+ Pokemod* pokemod = const_cast<Pokemod*>(static_cast<const Pokemod*>(static_cast<Object*>(treePokemod->currentIndex().internalPointer())->pokemod()));
KUrl url = KFileDialog::getSaveUrl(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMod files"), this, QString::fromUtf8("Open PokéMod"));
if (!url.isEmpty())
- treePokemod->savePokemod(static_cast<const Pokemod*>(object->pokemod()), url);
+ {
+ if (savePokemod(url))
+ treePokemod->setUrl(pokemod, url);
+ }
+}
+
+bool PokeModrUI::savePokemod(const KUrl& url)
+{
+ const Pokemod* pokemod = static_cast<const Pokemod*>(static_cast<Object*>(treePokemod->currentIndex().internalPointer())->pokemod());
+ if (url.isLocalFile())
+ {
+ QFile file(url.path());
+ if (file.open(QIODevice::ReadWrite))
+ {
+ file.write(Object::xml(pokemod).toByteArray());
+ file.close();
+ }
+ else
+ KMessageBox::error(this, QString::fromUtf8("Error saving the PokéMod!"), "Save error");
+ }
+ else
+ {
+ KTemporaryFile temp;
+ if (temp.open())
+ {
+ temp.write(Object::xml(pokemod).toByteArray());
+ if (!KIO::NetAccess::upload(temp.fileName(), url, this))
+ KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error");
+ }
+ else
+ KMessageBox::error(this, QString::fromUtf8("Error saving the PokéMod!"), "Save error");
+ }
}
void PokeModrUI::closePokeMod()