From ee4e0002025099edd716bbd5b5c4f21b467ac7ab Mon Sep 17 00:00:00 2001 From: Lukáš Lalinský Date: Mon, 20 Jul 2009 10:33:14 +0200 Subject: Open file passed on the command line --- src/diagramdocument.cpp | 10 +++- src/diagramdocument.h | 2 +- src/main.cpp | 8 ++- src/mainwindow.cpp | 20 ++++++-- src/mainwindow.h | 2 +- translations/dbmodel_en.ts | 120 +++++++++++++++++++++++---------------------- translations/dbmodel_sk.ts | 120 +++++++++++++++++++++++---------------------- 7 files changed, 154 insertions(+), 128 deletions(-) diff --git a/src/diagramdocument.cpp b/src/diagramdocument.cpp index a697bc7..a541d7a 100644 --- a/src/diagramdocument.cpp +++ b/src/diagramdocument.cpp @@ -432,15 +432,20 @@ DiagramDocument::save(const QString &fileName) #include "diagramitemfactory.h" -void +bool DiagramDocument::load(const QString &fileName) { QDomDocument doc; QFile file(fileName); if (file.open(QIODevice::ReadOnly)) { - doc.setContent(&file); + if (!doc.setContent(&file)) { + return false; + } file.close(); } + else { + return false; + } setFileName(fileName); QDomElement root = doc.firstChildElement("diagram"); @@ -460,6 +465,7 @@ DiagramDocument::load(const QString &fileName) } itemElement = itemElement.nextSiblingElement("item"); } + return true; } DiagramItem * diff --git a/src/diagramdocument.h b/src/diagramdocument.h index fa061b1..4a3fd34 100644 --- a/src/diagramdocument.h +++ b/src/diagramdocument.h @@ -72,7 +72,7 @@ public: QList selectedItems(); void save(const QString &fileName); - void load(const QString &fileName); + bool load(const QString &fileName); QString fileName() { return m_fileName; } void setFileName(const QString &fileName) { m_fileName = fileName; } diff --git a/src/main.cpp b/src/main.cpp index 628856c..a76a90c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,13 @@ main(int argc, char **argv) translator.load("dbmodel_" + QLocale::system().name(), ":/translations/"); app.installTranslator(&translator); - MainWindow window; + QString fileName; + QStringList args = app.arguments(); + if (args.size() > 1) { + fileName = args.at(1); + } + + MainWindow window(fileName); window.show(); return app.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index eac5f02..7d26984 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -68,14 +68,19 @@ public: ExporterList exporters; }; -MainWindow::MainWindow() +MainWindow::MainWindow(const QString &fileName) : QMainWindow(), d(new MainWindowPrivate), m_model(NULL) { setupUi(); setupActions(); setupToolBar(); setupMenuBar(); - newModel(); + if (fileName.isEmpty()) { + newModel(); + } + else { + loadFile(fileName); + } QIcon icon; icon.addFile(":/icons/16x16/item-table.png", QSize(32, 32)); @@ -448,9 +453,14 @@ void MainWindow::loadFile(const QString &fileName) { DiagramDocument *model = new DiagramDocument(this); - model->load(fileName); - newModel(model); - addRecentFile(fileName); + if (model->load(fileName)) { + newModel(model); + addRecentFile(fileName); + } + else { + QMessageBox::critical(this, tr("Error"), tr("Unknown format.")); + newModel(); + } } void diff --git a/src/mainwindow.h b/src/mainwindow.h index a1b7723..923f6cd 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -33,7 +33,7 @@ class MainWindow: public QMainWindow Q_OBJECT public: - MainWindow(); + MainWindow(const QString &fileName = QString()); ~MainWindow(); QIcon loadIcon(const QString &name); diff --git a/translations/dbmodel_en.ts b/translations/dbmodel_en.ts index ba60315..1adea7c 100644 --- a/translations/dbmodel_en.ts +++ b/translations/dbmodel_en.ts @@ -191,285 +191,287 @@ MainWindow - + &Properties - + &New - + Ctrl+N - + &Open... - + Ctrl+O - + &Save - + Ctrl+S - + Save &As... - + E&xport... - + Page Set&up... - + &Print... - + Ctrl+P - + Print Previe&w... - + Ctrl+Shift+P - + Select - + Add new table - + Add new relation - + &Undo - + Ctrl+Z - + Re&do - + Ctrl+Shift+Z - + Cu&t - + Ctrl+X - + &Copy - + Ctrl+C - + &Paste - + Ctrl+V - + &Delete - + Del - + &About... - + &Close - + Ctrl+W - + &Quit - + Ctrl+Q - + Show &Grid - + &Notation - + &Relational - + &Crow's Foot - - + + &File - + &Mode - + 50% - + 70% - + 85% - + 100% - + 125% - + 150% - - + + &View - + &Edit - + &Diagram - + &Help - + The document has been modified. Do you want to save your changes? - + + Error - + + Unknown format. - + &%1. %2 - + About - + <p> <b>Database Modeller @@ -484,7 +486,7 @@ Copyright (C) 2008 Lukas Lalinsky <p><b>Database Modeller</b><br /><a href="http://oxygene.sk/lukas/dbmodel/">http://oxygene.sk/lukas/dbmodel/</a><br />Copyright (C) 2008 Lukáš Lalinský</p> - + Untitled diff --git a/translations/dbmodel_sk.ts b/translations/dbmodel_sk.ts index 16b71e8..3433720 100644 --- a/translations/dbmodel_sk.ts +++ b/translations/dbmodel_sk.ts @@ -199,38 +199,38 @@ MainWindow - + &New &Nový - + Ctrl+N - + &Open... &Otvoriť... - + Ctrl+O - + &Save &Uložiť - + Ctrl+S - + Save &As... Uložiť &ako... @@ -239,256 +239,258 @@ Exportovať... - + Select Výber - + Add new table Pridať novú tabuľku - + Add new relation Pridať nový vzťah - + &Undo Vrátit &späť - + Ctrl+Z - + Re&do &Opakovať vrátené - + Ctrl+Shift+Z - - + + &File &Súbor - + &Mode &Mód - + 50% - + 70% - + 85% - + 100% - + 125% - + 150% - + &Quit &Koniec - + Ctrl+Q - + &Delete &Odstrániť - + Del - + + Error Chyba - + + Unknown format. Neznámy formát. - + &Edit &Upraviť - + E&xport... E&xportovať... - + Page Set&up... Nasta&venie stránky... - + &Print... &Tlačiť... - + Ctrl+P - + Print Previe&w... Ukážka pr&ed tlačou... - + Ctrl+Shift+P - + Cu&t Vystri&hnúť - + Ctrl+X - + &Copy &Kopírovať - + Ctrl+C - + &Paste &Vložiť - + Ctrl+V - - + + &View &Zobraziť - + The document has been modified. Do you want to save your changes? Dokument bol zmenený. Chcete uložiť Vaše zmeny? - + &%1. %2 - + &About... &O aplikácii... - + &Help &Pomocník - + About O aplikácii - + &Properties &Vlastnosti - + &Close Za&vrieť - + Ctrl+W - + Show &Grid Zobraziť m&riežku - + <p> <b>Database Modeller - + Untitled Nepomenované - + &Notation &Notácia - + &Relational &Relačná - + &Crow's Foot - + &Diagram -- cgit v1.2.3-54-g00ecf