diff --git a/src/qtgui/advsearch_w.cpp b/src/qtgui/advsearch_w.cpp index 25a7e5d2..14ecc550 100644 --- a/src/qtgui/advsearch_w.cpp +++ b/src/qtgui/advsearch_w.cpp @@ -356,18 +356,20 @@ void AdvSearch::saveFileTypes() void AdvSearch::browsePB_clicked() { - QString dir = myGetFileName(true); + auto topdirs = theconfig->getTopdirs(); + // if dirlocation is not empty, it's the last location set by the user, leave it alone + if (m_gfnparams.dirlocation.isEmpty() && !topdirs.empty()) { + m_gfnparams.dirlocation = u8s2qs(topdirs[0]); + } + m_gfnparams.sidedirs = topdirs; + m_gfnparams.readonly = true; + + m_gfnparams.caption = "Select directory"; + QString dir = myGetFileName(true, m_gfnparams); #ifdef _WIN32 string s = qs2utf8s(dir); - for (string::size_type i = 0; i < s.size(); i++) { - if (s[i] == '\\') { - s[i] = '/'; - } - } - if (s.size() >= 2 && isalpha(s[0]) && s[1] == ':') { - s.erase(1,1); - s = string("/") + s; - } + path_slashize(dir); + dir = path_slashdrive(dir); dir = u8s2qs(s); #endif subtreeCMB->setEditText(dir); diff --git a/src/qtgui/advsearch_w.h b/src/qtgui/advsearch_w.h index ca4c1da1..faaa88f3 100644 --- a/src/qtgui/advsearch_w.h +++ b/src/qtgui/advsearch_w.h @@ -78,7 +78,8 @@ private: bool m_ignByCats; QShortcut *m_histnextsc{nullptr}; QShortcut *m_histprevsc{nullptr}; - + MyGFNParams m_gfnparams; + void saveCnf(); void fillFileTypes(); size_t stringToSize(QString); diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 3218d4fb..011ab0c1 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 J.F.Dockes +/* Copyright (C) 2005-2022 J.F.Dockes * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -425,18 +425,27 @@ int main(int argc, char **argv) return app.exec(); } -QString myGetFileName(bool isdir, QString caption, bool filenosave, - QString dirloc, QString dfltnm) +QString myGetFileName(bool isdir, QString caption, bool filenosave, QString dirloc, QString dfltnm) { - LOGDEB1("myFileDialog: isdir " << isdir << "\n"); - QFileDialog dialog(0, caption); + MyGFNParams parms; + parms.caption = caption; + parms.filenosave = filenosave; + parms.dirlocation = dirloc; + parms.dfltnm = dfltnm; + return myGetFileName(isdir, parms); +} + +QString myGetFileName(bool isdir, MyGFNParams &parms) +{ + LOGDEB1("myGetFileName: isdir " << isdir << "\n"); + QFileDialog dialog(0, parms.caption); #ifdef _WIN32 - // The default initial directory on WIndows is the Recoll install, + // The default initial directory on Windows is the Recoll install, // which is not appropriate. Change it, only for the first call // (next will start with the previous selection). static bool first{true}; - if (first) { + if (first && parms.dirlocation.isEmpty()) { first = false; // See https://doc.qt.io/qt-5/qfiledialog.html#setDirectoryUrl // about the clsid magic (this one points to the desktop). @@ -444,22 +453,29 @@ QString myGetFileName(bool isdir, QString caption, bool filenosave, QUrl("clsid:B4BFCC3A-DB2C-424C-B029-7FE99A87C641")); } #endif - if (!dirloc.isEmpty()) { - dialog.setDirectory(dirloc); + if (!parms.dirlocation.isEmpty()) { + dialog.setDirectory(parms.dirlocation); } - if (!dfltnm.isEmpty()) { - dialog.selectFile(dfltnm); + if (!parms.dfltnm.isEmpty()) { + dialog.selectFile(parms.dfltnm); + } + + // DontUseNativeDialog is needed for sidebarurls + QFileDialog::Options opts = QFileDialog::DontUseNativeDialog; + if (parms.readonly) { + opts |= QFileDialog::ReadOnly; } if (isdir) { dialog.setFileMode(QFileDialog::Directory); - dialog.setOptions(QFileDialog::ShowDirsOnly); + opts |= QFileDialog::ShowDirsOnly; } else { dialog.setFileMode(QFileDialog::AnyFile); - if (filenosave) + if (parms.filenosave) dialog.setAcceptMode(QFileDialog::AcceptOpen); else dialog.setAcceptMode(QFileDialog::AcceptSave); } + dialog.setOptions(opts); dialog.setViewMode(QFileDialog::List); QFlags flags = QDir::NoDotAndDotDot | QDir::Hidden; if (isdir) @@ -468,7 +484,15 @@ QString myGetFileName(bool isdir, QString caption, bool filenosave, flags |= QDir::Dirs | QDir::Files; dialog.setFilter(flags); + if (!parms.sidedirs.empty()) { + QList sidebarurls; + for (const auto& dir : parms.sidedirs) { + sidebarurls.push_back(QUrl::fromLocalFile(path2qs(dir))); + } + dialog.setSidebarUrls(sidebarurls); + } if (dialog.exec() == QDialog::Accepted) { + parms.dirlocation = dialog.directory().absolutePath(); return dialog.selectedFiles().value(0); } return QString(); diff --git a/src/qtgui/recoll.h b/src/qtgui/recoll.h index 6cfa29f4..6214e9fa 100644 --- a/src/qtgui/recoll.h +++ b/src/qtgui/recoll.h @@ -75,12 +75,26 @@ inline std::string qs2path(const QString& qs) #endif } -/** Specialized version of the qt file dialog. Can't use getOpenFile() - etc. cause they hide dot files... */ +/** Specialized version of the qt file dialog. Can't use getOpenFile() etc. cause they hide dot + files... Need something more adaptable than the static functions but less complex than the full + dialog */ + +// Also : can't keep adding parms with default values, we now use an object as parameter. +class MyGFNParams { +public: + QString caption; + bool filenosave{false}; + QString dirlocation; // Note: this holds the new location on return + QString dfltnm; + std::vector sidedirs; + bool readonly{false}; +}; extern QString myGetFileName(bool isdir, QString caption = QString(), bool filenosave = false, QString dirlocation = QString(), QString dlftnm = QString() ); +extern QString myGetFileName(bool isdir, MyGFNParams &parms); + #endif /* _RECOLL_H_INCLUDED_ */ diff --git a/src/utils/rclutil.cpp b/src/utils/rclutil.cpp index 239f446e..07e161f6 100644 --- a/src/utils/rclutil.cpp +++ b/src/utils/rclutil.cpp @@ -325,6 +325,8 @@ string path_slashdrive(const string& path) npath.append(1, '/'); npath.append(path.substr(2)); } + } else { + npath = path; ///?? } return npath; }