summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-05-15 16:32:29 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-05-15 16:32:29 +0000
commit9b537cc98f99f9de4f153dd33f6561d5cd89b2a6 (patch)
tree95a59ebde842114fe5911c0db1c1a1d12a0335de
parent3db0d88626ef92b2f7dc24fb7db6503495749fbe (diff)
[FIX] Added more code for the main window
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@136 6ecfd1a5-f3ed-3746-8530-beee90d26b22
-rw-r--r--Changelog7
-rw-r--r--pokemodr/ObjectUI.h7
-rw-r--r--pokemodr/PokeModrUI.cpp75
-rw-r--r--pokemodr/PokeModrUI.h1
-rw-r--r--pokemodr/PokemodTree.cpp23
-rw-r--r--pokemodr/PokemodTree.h7
6 files changed, 98 insertions, 22 deletions
diff --git a/Changelog b/Changelog
index d8e91f4f..5519cd5e 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,11 @@
-----------------
+Rev: 136
+Date: 15 May 2008
+User: MathStuf
+-----------------
+[FIX] Added more code for the main window
+
+-----------------
Rev: 135
Date: 15 May 2008
User: MathStuf
diff --git a/pokemodr/ObjectUI.h b/pokemodr/ObjectUI.h
index cbe03bb9..6e754cf8 100644
--- a/pokemodr/ObjectUI.h
+++ b/pokemodr/ObjectUI.h
@@ -46,6 +46,13 @@ class ObjectUI : public QWidget
}
virtual ~ObjectUI()
{
+ if (m_changed)
+ {
+// if (KMessageBox::questionYesNo(this, "You have unsaved changes, would you like to save them?", QString("Unsaved %1").arg(m_object->className())) == KMessageBox::Yes)
+// on_buttonApply_clicked();
+// else
+// on_buttonDiscard_clicked();
+ }
delete m_object_mod;
}
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())
// {
diff --git a/pokemodr/PokeModrUI.h b/pokemodr/PokeModrUI.h
index b8b78267..36118d84 100644
--- a/pokemodr/PokeModrUI.h
+++ b/pokemodr/PokeModrUI.h
@@ -49,6 +49,7 @@ class PokeModrUI : public KMainWindow, private Ui::formPokeModr
void newPokemod();
void openPokemod();
void openPokemod(const KUrl& path);
+ bool openPokemod(const QString& path);
void savePokemod();
void saveAsPokemod();
void closePokeMod();
diff --git a/pokemodr/PokemodTree.cpp b/pokemodr/PokemodTree.cpp
index 8b7712d5..ad9c93e2 100644
--- a/pokemodr/PokemodTree.cpp
+++ b/pokemodr/PokemodTree.cpp
@@ -21,6 +21,9 @@
// Model includes
#include "models/BaseModel.h"
+// KDE includes
+#include <KUrl>
+
// Qt includes
#include <QHeaderView>
@@ -63,3 +66,23 @@ void PokemodTree::paste(const QModelIndex& index, const QDomDocument& data)
{
model()->setData(index, data.toString(), BaseModel::XmlRole);
}
+
+void PokemodTree::addPokemod(Pokemod* pokemod)
+{
+ // TODO: add the pokemod to the RootModel
+}
+
+void PokemodTree::deletePokemod(const Pokemod* pokemod)
+{
+ // TODO: delete the pokemod from the RootModel
+}
+
+void PokemodTree::savePokemod(const Pokemod* pokemod)
+{
+ // TODO: save the pokemod
+}
+
+void PokemodTree::savePokemod(const Pokemod* pokemod, const KUrl& url)
+{
+ // TODO: save the pokemod
+}
diff --git a/pokemodr/PokemodTree.h b/pokemodr/PokemodTree.h
index 7828680a..d8ee18a4 100644
--- a/pokemodr/PokemodTree.h
+++ b/pokemodr/PokemodTree.h
@@ -24,6 +24,8 @@
// Forward declarations
class KMenu;
+class KUrl;
+class Pokemod;
class PokemodTree : public QTreeView
{
@@ -39,6 +41,11 @@ class PokemodTree : public QTreeView
QDomDocument cut(const QModelIndex& index);
QDomDocument copy(const QModelIndex& index);
void paste(const QModelIndex& index, const QDomDocument& data);
+
+ void addPokemod(Pokemod* pokemod);
+ void deletePokemod(const Pokemod* pokemod);
+ void savePokemod(const Pokemod* pokemod);
+ void savePokemod(const Pokemod* pokemod, const KUrl& url);
};
#endif