From: Konrad Rosenbaum Date: Wed, 29 Feb 2012 21:11:18 +0000 (+0100) Subject: make file dialogs remember last directory X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=e90d63d2dc5aa8a087ced13d7e5aefd896361883;p=web%2Fkonrad%2Fsmoke.git make file dialogs remember last directory --- diff --git a/src/dialogs/configdialog.cpp b/src/dialogs/configdialog.cpp index a68968b..da7bf54 100644 --- a/src/dialogs/configdialog.cpp +++ b/src/dialogs/configdialog.cpp @@ -16,6 +16,7 @@ #include "office.h" #include "listview.h" #include "sslexception.h" +#include "misc.h" #include #include @@ -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() diff --git a/src/dialogs/eventsummary.cpp b/src/dialogs/eventsummary.cpp index e40d2b7..f44768f 100644 --- a/src/dialogs/eventsummary.cpp +++ b/src/dialogs/eventsummary.cpp @@ -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&))); diff --git a/src/dialogs/orderwin.cpp b/src/dialogs/orderwin.cpp index 522cc44..62647d1 100644 --- a/src/dialogs/orderwin.cpp +++ b/src/dialogs/orderwin.cpp @@ -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) diff --git a/src/misc/misc.cpp b/src/misc/misc.cpp index a4bea14..bbe8039 100644 --- a/src/misc/misc.cpp +++ b/src/misc/misc.cpp @@ -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 diff --git a/src/mwin/acltabs.cpp b/src/mwin/acltabs.cpp index 410f4d7..e433ead 100644 --- a/src/mwin/acltabs.cpp +++ b/src/mwin/acltabs.cpp @@ -59,6 +59,7 @@ #include #include #include +#include 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())); diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index 5e25794..860a510 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include diff --git a/src/mwin/tabwin.cpp b/src/mwin/tabwin.cpp index c7591c6..b25f14f 100644 --- a/src/mwin/tabwin.cpp +++ b/src/mwin/tabwin.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include diff --git a/src/templates/odfedit.cpp b/src/templates/odfedit.cpp index a6ce47d..d08066b 100644 --- a/src/templates/odfedit.cpp +++ b/src/templates/odfedit.cpp @@ -373,6 +373,7 @@ void MOdfEditor::saveFileAs() if(fn!=""){ d->mFileName=fn; saveFile(fn); + setCurrentDir(fn); } } diff --git a/src/templates/office.cpp b/src/templates/office.cpp index 01bbe9d..5354a55 100644 --- a/src/templates/office.cpp +++ b/src/templates/office.cpp @@ -11,6 +11,7 @@ // #include "office.h" +#include "misc.h" #include #include @@ -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); + } } diff --git a/src/templates/templatedlg.cpp b/src/templates/templatedlg.cpp index 4a7f72b..ff720f5 100644 --- a/src/templates/templatedlg.cpp +++ b/src/templates/templatedlg.cpp @@ -14,6 +14,7 @@ #include "ticketedit.h" #include "odfedit.h" #include "flagedit.h" +#include "misc.h" #include #include @@ -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)) diff --git a/src/templates/ticketedit.cpp b/src/templates/ticketedit.cpp index 3221fc8..e35732e 100644 --- a/src/templates/ticketedit.cpp +++ b/src/templates/ticketedit.cpp @@ -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)){