summaryrefslogtreecommitdiffstats
path: root/sigmodr/SigmodrUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-09-16 06:36:17 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-09-16 06:36:17 +0000
commitb5e31868dc0d4d5094752ab2dba127311434e66f (patch)
tree9ffa57312ec216426059ec16d011865e4c1af72f /sigmodr/SigmodrUI.cpp
parent0f0dbfb0395810c1c205a1dc10cf1f226669fd00 (diff)
[FIX] Refactored out some code to ObjectModel
[FIX] Drag and drop now accepts URLs [FIX] The main window can now accept drops git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@265 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigmodr/SigmodrUI.cpp')
-rw-r--r--sigmodr/SigmodrUI.cpp78
1 files changed, 66 insertions, 12 deletions
diff --git a/sigmodr/SigmodrUI.cpp b/sigmodr/SigmodrUI.cpp
index 92dfcfe4..17b6ce13 100644
--- a/sigmodr/SigmodrUI.cpp
+++ b/sigmodr/SigmodrUI.cpp
@@ -51,7 +51,10 @@
// Qt includes
#include <QtCore/QString>
+#include <QtCore/QUrl>
#include <QtGui/QCloseEvent>
+#include <QtGui/QDragEnterEvent>
+#include <QtGui/QDropEvent>
Sigmodr::SigmodrUI::SigmodrUI(QWidget* parent) :
KXmlGuiWindow(parent),
@@ -59,6 +62,7 @@ Sigmodr::SigmodrUI::SigmodrUI(QWidget* parent) :
{
setupUi(this);
setupActions();
+ setAcceptDrops(true);
buttonApply->setIcon(KIcon("dialog-ok-apply"));
buttonReset->setIcon(KIcon("edit-undo"));
splitter->setSizes(QList<int>() << m_config.readEntry("treeWidth", 100) << m_config.readEntry("panelWidth", 100));
@@ -136,19 +140,24 @@ bool Sigmodr::SigmodrUI::openSigmod(const KUrl& url)
KMessageBox::error(this, "File is already opened", "Sigmod error");
return false;
}
- if (url.isLocalFile())
- opened = openSigmod(url.path());
- else
+ if (url.isValid())
{
- QString temp;
- if (KIO::NetAccess::download(url, temp, this))
+ if (url.isLocalFile())
+ opened = openSigmod(url.path());
+ else
{
- opened = openSigmod(temp, true);
- KIO::NetAccess::removeTempFile(temp);
+ QString temp;
+ if (KIO::NetAccess::download(url, temp, this))
+ {
+ opened = openSigmod(temp, true);
+ KIO::NetAccess::removeTempFile(temp);
+ }
+ else
+ KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error");
}
- else
- KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error");
}
+ else
+ KMessageBox::error(this, "The URL is not valid", "Malformed URL");
if (opened)
qobject_cast<KRecentFilesAction*>(actionCollection()->action(KStandardAction::name(KStandardAction::OpenRecent)))->addUrl(url);
return opened;
@@ -160,7 +169,10 @@ bool Sigmodr::SigmodrUI::openSigmod(const QString& path, const bool isRemote)
if (file.open(QIODevice::ReadOnly))
{
QDomDocument xml;
- if (xml.setContent(&file))
+ QString error;
+ int line;
+ int column;
+ if (xml.setContent(&file, &error, &line, &column))
{
if (xml.doctype().name() == "Sigmod")
{
@@ -171,11 +183,11 @@ bool Sigmodr::SigmodrUI::openSigmod(const QString& path, const bool isRemote)
KMessageBox::error(this, "The file is not a Sigmod.", "Invalid Sigmod");
}
else
- KMessageBox::error(this, "The file is not a valid XML file.", "Invalid Sigmod");
+ KMessageBox::error(this, QString("%1 at line %2, column %3").arg(error).arg(line).arg(column), "XML Error");
file.close();
}
else
- KMessageBox::error(this, QString("Cannot open file:\n%1").arg(path), "No such file");
+ KMessageBox::error(this, file.errorString(), "File Error");
return false;
}
@@ -226,6 +238,7 @@ bool Sigmodr::SigmodrUI::saveSigmod(const Sigmod::Sigmod* sigmod, const KUrl& ur
}
else
KMessageBox::error(this, "Error saving the Sigmod!", "Save error");
+ temp.close();
}
}
return false;
@@ -415,6 +428,47 @@ void Sigmodr::SigmodrUI::on_treeSigmod_customContextMenuRequested(const QPoint&
}
}
+void Sigmodr::SigmodrUI::dragEnterEvent(QDragEnterEvent* event)
+{
+ const QMimeData* data = event->mimeData();
+ if (data->hasFormat("application/x-sigmod+xml") || data->hasFormat("text/uri-list"))
+ event->acceptProposedAction();
+}
+
+void Sigmodr::SigmodrUI::dropEvent(QDropEvent* event)
+{
+ const QMimeData* data = event->mimeData();
+ bool loaded = false;
+ event->setDropAction(Qt::CopyAction);
+ if (data->hasFormat("application/x-sigmod+xml"))
+ {
+ QDomDocument xml;
+ QString error;
+ int line;
+ int column;
+ if (xml.setContent(data->data("application/x-sigmod+xml"), &error, &line, &column))
+ {
+ if (xml.doctype().name() == "Sigmod")
+ {
+ treeSigmod->addSigmod(new Sigmod::Sigmod(xml.documentElement()));
+ loaded = true;
+ }
+ else
+ KMessageBox::error(this, "The file is not a Sigmod.", "Invalid Sigmod");
+ }
+ else
+ KMessageBox::error(this, QString("%1 at line %2, column %3").arg(error).arg(line).arg(column), "XML Error");
+ }
+ else if (data->hasFormat("text/uri-list"))
+ {
+ QList<QUrl> urls = data->urls();
+ foreach (QUrl url, urls)
+ loaded = openSigmod(url);
+ }
+ if (loaded)
+ event->acceptProposedAction();
+}
+
void Sigmodr::SigmodrUI::setupActions()
{
KStandardAction::openNew(this, SLOT(newSigmod()), actionCollection());