summaryrefslogtreecommitdiffstats
path: root/pokemodr/PokeModrUI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemodr/PokeModrUI.cpp')
-rw-r--r--pokemodr/PokeModrUI.cpp75
1 files changed, 53 insertions, 22 deletions
diff --git a/pokemodr/PokeModrUI.cpp b/pokemodr/PokeModrUI.cpp
index 80341383..74e68eb3 100644
--- a/pokemodr/PokeModrUI.cpp
+++ b/pokemodr/PokeModrUI.cpp
@@ -42,6 +42,7 @@
#include <KStandardDirs>
#include <KToolBar>
#include <KUrl>
+#include <KIO/NetAccess>
PokeModrUI::PokeModrUI(KConfigGroup config, KConfigGroup history, QWidget* parent) :
KMainWindow(parent),
@@ -140,53 +141,83 @@ void PokeModrUI::setChangedTitle(const bool changed)
void PokeModrUI::newPokemod()
{
- // TODO: add a blank pokemod to the tree
+ treePokemod->addPokemod(new Pokemod());
}
void PokeModrUI::openPokemod()
{
- QFile file(KFileDialog::getOpenFileName(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMods"), this));
- if (file.open(QIODevice::ReadOnly))
+ QString path(KFileDialog::getOpenFileName(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMod files"), this));
+ if (!path.isEmpty())
{
- // TODO: open the file into the tree
- file.close();
+ if (openPokemod(path))
+ {
+ m_recent->addUrl(path);
+ m_recent->saveEntries(m_config);
+ }
}
}
void PokeModrUI::openPokemod(const KUrl& path)
{
if (path.isLocalFile())
+ openPokemod(path.path());
+ else
{
-// m_pokemods.append(new Pokemod(path.path()));
- m_recent->addUrl(path);
- m_recent->saveEntries(m_config);
+ QString temp;
+ if (KIO::NetAccess::download(path, temp, this))
+ {
+ if (openPokemod(temp))
+ {
+ m_recent->addUrl(path);
+ m_recent->saveEntries(m_config);
+ }
+ KIO::NetAccess::removeTempFile(temp);
+ }
+ else
+ KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error");
}
}
+bool PokeModrUI::openPokemod(const QString& path)
+{
+ QFile file(path);
+ if (file.open(QIODevice::ReadOnly))
+ {
+ QDomDocument xml;
+ if (xml.setContent(&file))
+ {
+ if (xml.doctype().name() == "Pokemod")
+ {
+ treePokemod->addPokemod(new Pokemod(xml.documentElement()));
+ return true;
+ }
+ else
+ KMessageBox::error(this, QString::fromUtf8("The file is not a PokéMod."), QString::fromUtf8("Invalid PokéMod"));
+ }
+ else
+ KMessageBox::error(this, "The file is not a valid XML file.", QString::fromUtf8("Invalid PokéMod"));
+ file.close();
+ }
+ return false;
+}
+
void PokeModrUI::savePokemod()
{
- // TODO: Save the current pokemod with the object open
-// if (!treePokemod->currentItem())
-// return;
-// static_cast<PokeModTreeItem*>(treePokemod->currentItem())->save();
-// static_cast<Pokemod*>(static_cast<PokeModTreeItem*>(treePokemod->currentItem())->object())->pokemod()->save();
+ Object* object = static_cast<Object*>(treePokemod->currentIndex().internalPointer());
+ treePokemod->savePokemod(static_cast<const Pokemod*>(object->pokemod()));
}
void PokeModrUI::saveAsPokemod()
{
- // TODO: Save the current pokemod to a new file
-// if (!treePokemod->currentItem())
-// return;
-// QString dir = KFileDialog::existingDirectory(KUrl(KStandardDirs::locateLocal("data", "pokegen/pokemods", true)), this, QString::fromUtf8("Open PokéMod"));
-// if (dir != "")
-// {
-// static_cast<PokeModTreeItem*>(treePokemod->currentItem())->save();
-// static_cast<PokeModTreeItem*>(treePokemod->currentItem())->pokemod()->setPath(dir);
-// }
+ Object* object = static_cast<Object*>(treePokemod->currentIndex().internalPointer());
+ 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);
}
void PokeModrUI::closePokeMod()
{
+
// TODO: Close the Pokemod with the current editor open
// if (formPanel->widget())
// {