make file dialogs remember last directory
authorKonrad Rosenbaum <konrad@silmor.de>
Wed, 29 Feb 2012 21:11:18 +0000 (22:11 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Wed, 29 Feb 2012 21:11:18 +0000 (22:11 +0100)
src/dialogs/configdialog.cpp
src/dialogs/eventsummary.cpp
src/dialogs/orderwin.cpp
src/misc/misc.cpp
src/mwin/acltabs.cpp
src/mwin/overview.cpp
src/mwin/tabwin.cpp
src/templates/odfedit.cpp
src/templates/office.cpp
src/templates/templatedlg.cpp
src/templates/ticketedit.cpp

index a68968b..da7bf54 100644 (file)
@@ -16,6 +16,7 @@
 #include "office.h"
 #include "listview.h"
 #include "sslexception.h"
+#include "misc.h"
 
 #include <QByteArray>
 #include <QCheckBox>
@@ -441,9 +442,11 @@ void MConfigDialog::saveKey(QString host,QString key)
        fdlg.setDefaultSuffix("mshk");
        fdlg.setAcceptMode(QFileDialog::AcceptSave);
        fdlg.setFileMode(QFileDialog::AnyFile);
+       fdlg.setDirectory(currentDir());
        if(!fdlg.exec())return;
        fn=fdlg.selectedFiles();
        if(fn.size()!=1)return;
+       setCurrentDir(fn[0]);
        QFile fd(fn[0]);
        if(!fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){
                QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for writing: %2").arg(fn[0]).arg(fd.errorString()));
@@ -468,9 +471,11 @@ void MConfigDialog::importKey()
        fdlg.setDefaultSuffix("mshk");
        fdlg.setAcceptMode(QFileDialog::AcceptOpen);
        fdlg.setFileMode(QFileDialog::ExistingFile);
+       fdlg.setDirectory(currentDir());
        if(!fdlg.exec())return;
        fn=fdlg.selectedFiles();
        if(fn.size()!=1)return;
+       setCurrentDir(fn[0]);
        QFile fd(fn[0]);
        if(!fd.open(QIODevice::ReadOnly)){
                QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for reading: %2").arg(fn[0]).arg(fd.errorString()));
@@ -642,8 +647,11 @@ MAppStyleDialog::MAppStyleDialog(QWidget*par)
 
 void MAppStyleDialog::selectCSS()
 {
-       QString s=QFileDialog::getOpenFileName(this,tr("Select Stylesheet"));
-       if(s!="")css->setText(s);
+       QString s=QFileDialog::getOpenFileName(this,tr("Select Stylesheet"),currentDir());
+       if(s!=""){
+               css->setText(s);
+               setCurrentDir(s);
+       }
 }
 
 void MAppStyleDialog::save()
index e40d2b7..f44768f 100644 (file)
@@ -195,11 +195,13 @@ void MEventSummary::saveas()
        fd.setConfirmOverwrite(true);
        fd.setFilter(tr("Open Document File (*.%1)").arg(tf.targetExtension()));
        fd.setDefaultSuffix(tf.targetExtension());
+       fd.setDirectory(currentDir());
        QString fname;
        if(fd.exec()){
                QStringList fn=fd.selectedFiles();
                if(fn.size()<1)return;
                fname=fn[0];
+               setCurrentDir(fname);
        }
        MOdtSignalRenderer rend(tf);
        connect(&rend,SIGNAL(getVariable(QString,QVariant&)), this,SLOT(getVariable(QString,QVariant&)));
index 522cc44..62647d1 100644 (file)
@@ -452,11 +452,13 @@ void MOrderWindow::saveBill()
        fd.setConfirmOverwrite(true);
        fd.setFilter(tr("Open Document File (*.%1)").arg(tf.targetExtension()));
        fd.setDefaultSuffix(tf.targetExtension());
+       fd.setDirectory(currentDir());
        QString fname;
        if(fd.exec()){
                QStringList fn=fd.selectedFiles();
                if(fn.size()<1)return;
                fname=fn[0];
+               setCurrentDir(fname);
        }
        //mark order as shipped?
        if(m_order.status()==MOOrder::Placed)
index a4bea14..bbe8039 100644 (file)
@@ -690,7 +690,7 @@ void setCurrentDir(QString fn)
        if(fn.isEmpty())return;
        QFileInfo fi(fn);
        //it is already a directory
-       if(fi.isDir())QSettings().setValue("lastUsedDirectory",fn);
+       if(fi.isDir())QSettings().setValue("lastUsedDirectory",fi.absoluteFilePath());
        //it is probably a file
        else {
                //get parent directory name
index 410f4d7..e433ead 100644 (file)
@@ -59,6 +59,7 @@
 #include <QPushButton>
 #include <QStandardItemModel>
 #include <QTableView>
+#include <misc.h>
 
 MUserTab::MUserTab(QString pk)
 {
@@ -454,9 +455,11 @@ void MHostTab::changeHostKey()
        fdlg.setDefaultSuffix("mshk");
        fdlg.setAcceptMode(QFileDialog::AcceptSave);
        fdlg.setFileMode(QFileDialog::AnyFile);
+       fdlg.setDirectory(currentDir());
        if(!fdlg.exec())return;
        fn=fdlg.selectedFiles();
        if(fn.size()!=1)return;
+       setCurrentDir(fn[0]);
        QFile fd(fn[0]);
        if(!fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){
                QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for writing: %2").arg(fn[0]).arg(fd.errorString()));
@@ -485,9 +488,11 @@ void MHostTab::importHost()
        fdlg.setDefaultSuffix("mshk");
        fdlg.setAcceptMode(QFileDialog::AcceptOpen);
        fdlg.setFileMode(QFileDialog::ExistingFile);
+       fdlg.setDirectory(currentDir());
        if(!fdlg.exec())return;
        fn=fdlg.selectedFiles();
        if(fn.size()!=1)return;
+       setCurrentDir(fn[0]);
        QFile fd(fn[0]);
        if(!fd.open(QIODevice::ReadOnly)){
                QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for reading: %2").arg(fn[0]).arg(fd.errorString()));
@@ -570,9 +575,11 @@ void MHostTab::exportHost()
        fdlg.setDefaultSuffix("mshh");
        fdlg.setAcceptMode(QFileDialog::AcceptSave);
        fdlg.setFileMode(QFileDialog::AnyFile);
+       fdlg.setDirectory(currentDir());
        if(!fdlg.exec())return;
        fn=fdlg.selectedFiles();
        if(fn.size()!=1)return;
+       setCurrentDir(fn[0]);
        QFile fd(fn[0]);
        if(!fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){
                QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for writing: %2").arg(fn[0]).arg(fd.errorString()));
index 5e25794..860a510 100644 (file)
@@ -41,7 +41,6 @@
 #include <QComboBox>
 #include <QDebug>
 #include <QFile>
-#include <QFileDialog>
 #include <QGroupBox>
 #include <QInputDialog>
 #include <QLabel>
index c7591c6..b25f14f 100644 (file)
@@ -37,7 +37,6 @@
 #include <QComboBox>
 #include <QDebug>
 #include <QFile>
-#include <QFileDialog>
 #include <QGroupBox>
 #include <QInputDialog>
 #include <QLabel>
index a6ce47d..d08066b 100644 (file)
@@ -373,6 +373,7 @@ void MOdfEditor::saveFileAs()
        if(fn!=""){
                d->mFileName=fn;
                saveFile(fn);
+               setCurrentDir(fn);
        }
 }
 
index 01bbe9d..5354a55 100644 (file)
@@ -11,6 +11,7 @@
 //
 
 #include "office.h"
+#include "misc.h"
 
 #include <QBoxLayout>
 #include <QCheckBox>
@@ -89,10 +90,11 @@ void printOfficeFile(QString fname)
        proc.waitForFinished();
        //copy file
        if(QSettings().value("officePrinterSave",false).toBool()){
-               QString fn=QFileDialog::getSaveFileName(0,QCoreApplication::translate("office","Save current document as..."));
+               QString fn=QFileDialog::getSaveFileName(0,QCoreApplication::translate("office","Save current document as..."),currentDir());
                if(fn=="")return;
                QFile(fn).remove();
                QFile(fname).copy(fn);
+               setCurrentDir(fn);
        }
 }
 
@@ -171,5 +173,8 @@ void MOfficeConfig::savedata()
 void MOfficeConfig::selectpath()
 {
        QString np=QFileDialog::getOpenFileName(this,tr("Select OpenOffice.org executable"),QFileInfo(oopath->text()).dir().absolutePath());
-       if(np!="")oopath->setText(np);
+       if(np!=""){
+               oopath->setText(np);
+               setCurrentDir(np);
+       }
 }
index 4a7f72b..ff720f5 100644 (file)
@@ -14,6 +14,7 @@
 #include "ticketedit.h"
 #include "odfedit.h"
 #include "flagedit.h"
+#include "misc.h"
 
 #include <QBoxLayout>
 #include <QComboBox>
@@ -198,8 +199,9 @@ void MTemplateEditor::addItem()
        QString base=model->data(bidx,BASEROLE).toString();
        if(base=="")return;
        //query file name
-       QString fn=QFileDialog::getOpenFileName(this,tr("Select Template File"));
+       QString fn=QFileDialog::getOpenFileName(this,tr("Select Template File"),currentDir());
        if(fn=="")return;
+       setCurrentDir(fn);
        //check extension
        QString ext=QFileInfo(fn).completeSuffix();
        if(!MTemplate::legalSuffixes(base).contains(ext)){
@@ -313,11 +315,13 @@ void MTemplateEditor::saveItem()
                QFileDialog fd(this,tr("Save template as..."));
                fd.setAcceptMode(QFileDialog::AcceptSave);
                fd.setDefaultSuffix(tmp.extension());
+               fd.setDirectory(currentDir());
                fd.selectFile(tmp.baseName());
                if(fd.exec()!=QDialog::Accepted)
                        return;
                nfn=fd.selectedFiles().at(0);
                if(nfn=="")return;
+               setCurrentDir(nfn);
        }
        //store it
        if(!QFile::copy(fn,nfn))
index 3221fc8..e35732e 100644 (file)
@@ -423,10 +423,11 @@ void MTicketEditor::parseTemplate(QByteArray bytes)
 
 void MTicketEditor::openFile()
 {
-       QString fn=QFileDialog::getOpenFileName(this,tr("Open Ticket Template"));
+       QString fn=QFileDialog::getOpenFileName(this,tr("Open Ticket Template"),currentDir());
        if(fn!=""){
                d->mFileName=fn;
                loadFile(fn);
+               setCurrentDir(fn);
        }
 }
 
@@ -453,6 +454,7 @@ void MTicketEditor::saveFileAs()
        if(fn!=""){
                d->mFileName=fn;
                saveFile(fn);
+               setCurrentDir(fn);
        }
 }
 
@@ -808,8 +810,9 @@ void MTicketEditor::saveXmlPart(QIODevice& fd)
 
 void MTicketEditor::addFile()
 {
-       QString fn=QFileDialog::getOpenFileName(this,tr("Add File to Label"));
+       QString fn=QFileDialog::getOpenFileName(this,tr("Add File to Label"),currentDir());
        if(fn=="")return;
+       setCurrentDir(fn);
        //try to read it
        QFile fd(fn);
        if(!fd.open(QIODevice::ReadOnly)){