Add option to open files from the commandline.

This commit is contained in:
Jos van den Oever
2010-06-24 10:48:55 +02:00
parent 63ad205265
commit 759291d347
3 changed files with 26 additions and 15 deletions
+22 -15
View File
@@ -6,6 +6,7 @@
#include <QtGui/QFileSystemModel>
#include <QtGui/QTreeView>
#include <QtGui/QDockWidget>
#include <QtCore/QDir>
#include <QtCore/QDebug>
MainWindow::MainWindow(QWidget *parent) :
@@ -32,7 +33,7 @@ MainWindow::MainWindow(QWidget *parent) :
for (int i = 1; i < dirmodel->columnCount(); i++) {
dirview->setColumnHidden(i, true);
}
QString rootpath = "/home/oever/work/odfkit/odfkit/javascriptzip/kofficetests";
QString rootpath = QDir::homePath();
dirmodel->setRootPath(rootpath);
const QModelIndex rootindex = dirmodel->index(rootpath);
dirview->setRootIndex(rootindex);
@@ -54,6 +55,25 @@ MainWindow::~MainWindow()
delete ui;
}
void
MainWindow::openFile(const QString& path)
{
QMdiSubWindow* w = findMdiChild(path);
OdfView* v = (w) ?dynamic_cast<OdfView*>(w->widget()) :0;
if (v == 0) {
w = ui->mdiArea->activeSubWindow();
v = (w) ?dynamic_cast<OdfView*>(w->widget()) :0;
}
if (v == 0) {
v = new OdfView(this);
v->showMaximized();
w = ui->mdiArea->addSubWindow(v);
w->showMaximized();
}
ui->mdiArea->setActiveSubWindow(w);
v->loadFile(path);
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
@@ -128,18 +148,5 @@ MainWindow::loadOdf(const QModelIndex& index) {
}
QString path = dirmodel->filePath(index);
path = QFileInfo(path).canonicalFilePath();
QMdiSubWindow* w = findMdiChild(path);
OdfView* v = (w) ?dynamic_cast<OdfView*>(w->widget()) :0;
if (v == 0) {
w = ui->mdiArea->activeSubWindow();
v = (w) ?dynamic_cast<OdfView*>(w->widget()) :0;
}
if (v == 0) {
v = new OdfView(this);
v->showMaximized();
w = ui->mdiArea->addSubWindow(v);
w->showMaximized();
}
ui->mdiArea->setActiveSubWindow(w);
v->loadFile(path);
openFile(path);
}