summaryrefslogtreecommitdiffstats
path: root/pokemodr/PokeModrUI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemodr/PokeModrUI.cpp')
-rw-r--r--pokemodr/PokeModrUI.cpp52
1 files changed, 30 insertions, 22 deletions
diff --git a/pokemodr/PokeModrUI.cpp b/pokemodr/PokeModrUI.cpp
index debb95bf..1367beef 100644
--- a/pokemodr/PokeModrUI.cpp
+++ b/pokemodr/PokeModrUI.cpp
@@ -20,6 +20,7 @@
// PokeModr includes
#include "ObjectUI.h"
+#include "PokeModrPreferences.h"
#include "PokemodTreeModel.h"
// Pokemod includes
@@ -47,33 +48,34 @@
#include <KUrl>
#include <KIO/NetAccess>
-PokeModrUI::PokeModrUI(KConfigGroup config, QWidget* parent) :
+PokeModrUI::PokeModrUI(QWidget* parent) :
KMainWindow(parent),
- m_config(config)
+ m_config(KGlobal::config()->group("pokemodr"))
{
setupUi(this);
setupActions();
- splitter->setSizes(QList<int>() << config.readEntry("treeWidth", 100) << config.readEntry("panelWidth", 100));
+ splitter->setSizes(QList<int>() << m_config.readEntry("treeWidth", 100) << m_config.readEntry("panelWidth", 100));
connect(buttonApply, SIGNAL(clicked()), this, SLOT(update()));
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
- if (args)
+ if (args && args->count())
{
for(int i = 0; i < args->count(); ++i)
openPokemod(args->url(i));
args->clear();
}
- if (config.readEntry("reloadOnStart", false))
+ else if (m_config.readEntry("reloadOnStart", false))
{
- for (int i = 0; i < config.readEntry("openedFiles", 0); ++i)
- openPokemod(m_recent->urls().at(i));
+ QStringList urls = m_config.readEntry("Opened Files", QStringList());
+ foreach (QString url, urls)
+ openPokemod(KUrl(url));
}
setAutoSaveSettings("MainWindow", true);
}
PokeModrUI::~PokeModrUI()
{
+ m_config.config()->sync();
closeAllPokemods(true);
- m_recent->saveEntries(m_config);
}
void PokeModrUI::update()
@@ -83,6 +85,7 @@ void PokeModrUI::update()
void PokeModrUI::closeEvent(QCloseEvent* event)
{
+ m_recent->saveEntries(m_config.group("Recent Files"));
if (closeAllPokemods())
event->accept();
else
@@ -107,37 +110,38 @@ void PokeModrUI::newPokemod()
void PokeModrUI::openPokemod()
{
- KUrl::List urls(KFileDialog::getOpenUrls(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMod files"), this));
+ KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMod files"), this);
foreach (KUrl url, urls)
{
if (!url.isEmpty())
- {
- if (openPokemod(url))
- {
- m_recent->addUrl(url);
- m_recent->saveEntries(m_config);
- }
- }
+ openPokemod(url);
}
}
bool PokeModrUI::openPokemod(const KUrl& url)
{
+ bool opened = false;
+ if (treePokemod->isOpen(url))
+ {
+ KMessageBox::error(this, "File is already opened", QString::fromUtf8("PokéMod error"));
+ return false;
+ }
if (url.isLocalFile())
- return openPokemod(url.path());
+ opened = openPokemod(url.path());
else
{
QString temp;
if (KIO::NetAccess::download(url, temp, this))
{
- const bool opened = openPokemod(temp, true);
+ opened = openPokemod(temp, true);
KIO::NetAccess::removeTempFile(temp);
- return opened;
}
else
KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error");
}
- return false;
+ if (opened)
+ m_recent->addUrl(url);
+ return opened;
}
bool PokeModrUI::openPokemod(const QString& path, const bool isRemote)
@@ -271,6 +275,8 @@ bool PokeModrUI::closePokemod(const Pokemod* pokemod, const bool force)
bool PokeModrUI::closeAllPokemods(const bool force)
{
QList<const Pokemod*> pokemods = treePokemod->openedPokemods();
+ if (pokemods.size())
+ m_config.writeEntry("Opened Files", treePokemod->urls());
for (int i = 0; i < pokemods.size(); )
{
if (closePokemod(pokemods[i], force))
@@ -295,7 +301,9 @@ void PokeModrUI::pasteObject()
void PokeModrUI::preferences()
{
- // TODO: preferences
+ PokeModrPreferences* dialog = new PokeModrPreferences(this, m_config);
+ connect(dialog, SIGNAL(okClicked()), dialog, SLOT(save()));
+ dialog->exec();
}
void PokeModrUI::on_splitter_splitterMoved()
@@ -365,7 +373,7 @@ void PokeModrUI::setupActions()
KAction* openNew = KStandardAction::openNew(this, SLOT(newPokemod()), this);
KAction* open = KStandardAction::open(this, SLOT(openPokemod()), this);
m_recent = KStandardAction::openRecent(this, SLOT(openPokemod(const KUrl&)), this);
- m_recent->loadEntries(m_config);
+ m_recent->loadEntries(m_config.group("Recent Files"));
KAction* close = KStandardAction::close(this, SLOT(closePokemod()), this);
KAction* save = KStandardAction::save(this, SLOT(savePokemod()), this);
KAction* saveAs = KStandardAction::saveAs(this, SLOT(saveAsPokemod()), this);