From 01b2893f8beef6a9716195ee5e7b42c75e135fae Mon Sep 17 00:00:00 2001 From: Daniel Ramoeller Date: Wed, 12 Aug 2020 14:24:40 -0400 Subject: [PATCH] Fix bug #10346. Allow to open user and library directories from About LyX. --- src/frontends/qt/GuiAbout.cpp | 77 +++++++++++----- src/frontends/qt/GuiAbout.h | 3 + src/frontends/qt/GuiLog.cpp | 16 +--- src/frontends/qt/qt_helpers.cpp | 17 ++++ src/frontends/qt/qt_helpers.h | 2 + src/frontends/qt/ui/AboutUi.ui | 151 +++++++++++++++++++++++++++++--- 6 files changed, 215 insertions(+), 51 deletions(-) diff --git a/src/frontends/qt/GuiAbout.cpp b/src/frontends/qt/GuiAbout.cpp index a641e9ad87..25c3a689dd 100644 --- a/src/frontends/qt/GuiAbout.cpp +++ b/src/frontends/qt/GuiAbout.cpp @@ -11,6 +11,7 @@ #include #include "GuiAbout.h" +#include "GuiApplication.h" #include "ui_AboutUi.h" @@ -22,6 +23,7 @@ #include "support/lstrings.h" #include "support/Package.h" +#include #include #include #include @@ -196,6 +198,33 @@ static QString disclaimer() } +static QString buildinfo() +{ + QString res; + QTextStream out(&res); + out << "LyX " << lyx_version + << " (" << lyx_release_date << ")" << endl; + if (std::string(lyx_git_commit_hash) != "none") + out << qt_(" Git commit hash ") + << QString(lyx_git_commit_hash).left(8) << endl; + + out << lyx_version_info << endl; + return res; +} + + +static QString dirLibrary() +{ + return toqstr(makeDisplayPath(package().system_support().absFileName())); +} + + +static QString dirUser() +{ + return toqstr(makeDisplayPath(package().user_support().absFileName())); +} + + static QString version() { QString loc_release_date; @@ -216,33 +245,12 @@ static QString version() if (std::string(lyx_git_commit_hash) != "none") version_date += _("Built from git commit hash ") + from_utf8(lyx_git_commit_hash).substr(0,8); - version_date += "\n"; QString res; QTextStream out(&res); - out << toqstr(version_date); - out << qt_("Library directory: "); - out << toqstr(makeDisplayPath(package().system_support().absFileName())); - out << "\n"; - out << qt_("User directory: "); - out << toqstr(makeDisplayPath(package().user_support().absFileName())); - out << "\n"; + out << toqstr(version_date) << "\n"; out << toqstr(bformat(_("Qt Version (run-time): %1$s"), from_ascii(qVersion()))) << "\n"; - out << toqstr(bformat(_("Qt Version (compile-time): %1$s"), from_ascii(QT_VERSION_STR))) << "\n"; - return res; -} - -static QString buildinfo() -{ - QString res; - QTextStream out(&res); - out << "LyX " << lyx_version - << " (" << lyx_release_date << ")" << endl; - if (std::string(lyx_git_commit_hash) != "none") - out << qt_(" Git commit hash ") - << QString(lyx_git_commit_hash).left(8) << endl; - - out << lyx_version_info << endl; + out << toqstr(bformat(_("Qt Version (compile-time): %1$s"), from_ascii(QT_VERSION_STR))); return res; } @@ -252,6 +260,24 @@ struct GuiAbout::Private Ui::AboutUi ui; }; +void GuiAbout::on_showDirLibraryPB_clicked() +{ + showDirectory(package().system_support()); +} + + +void GuiAbout::on_showDirUserPB_clicked() +{ + showDirectory(package().user_support()); +} + + +void GuiAbout::on_versionCopyPB_clicked() +{ + QClipboard *clipboard = QGuiApplication::clipboard(); + clipboard->setText(version()); +} + GuiAbout::GuiAbout(GuiView & lv) : DialogView(lv, "aboutlyx", qt_("About LyX")), @@ -259,6 +285,9 @@ GuiAbout::GuiAbout(GuiView & lv) { d->ui.setupUi(this); + // fix height to minimum + setFixedHeight(sizeHint().height()); + d->ui.copyrightTB->setPlainText(copyright()); d->ui.copyrightTB->append(QString()); d->ui.copyrightTB->append(license()); @@ -266,6 +295,8 @@ GuiAbout::GuiAbout(GuiView & lv) d->ui.copyrightTB->append(disclaimer()); d->ui.versionLA->setText(version()); + d->ui.dirLibraryLA->setText(dirLibrary()); + d->ui.dirUserLA->setText(dirUser()); d->ui.buildinfoTB->setText(buildinfo()); d->ui.releasenotesTB->setHtml(release_notes()); d->ui.releasenotesTB->setOpenExternalLinks(true); diff --git a/src/frontends/qt/GuiAbout.h b/src/frontends/qt/GuiAbout.h index 200f0b7837..acd485fe89 100644 --- a/src/frontends/qt/GuiAbout.h +++ b/src/frontends/qt/GuiAbout.h @@ -27,6 +27,9 @@ public: private Q_SLOTS: void on_buttonBox_rejected(); + void on_showDirLibraryPB_clicked(); + void on_showDirUserPB_clicked(); + void on_versionCopyPB_clicked(); private: /// Controller stuff diff --git a/src/frontends/qt/GuiLog.cpp b/src/frontends/qt/GuiLog.cpp index 341f06c8ce..86828067d4 100644 --- a/src/frontends/qt/GuiLog.cpp +++ b/src/frontends/qt/GuiLog.cpp @@ -25,10 +25,8 @@ #include "support/gettext.h" #include "support/lstrings.h" -#include #include #include -#include #include #include @@ -191,18 +189,8 @@ void GuiLog::on_nextWarningPB_clicked() void GuiLog::on_openDirPB_clicked() -{ - support::FileName dir = logfile_.onlyPath(); - if (!dir.exists()) - return; - QUrl qdir(QUrl::fromLocalFile(toqstr(from_utf8(dir.absFileName())))); - // Give hints in case of bugs - if (!qdir.isValid()) { - LYXERR0("QUrl is invalid!"); - return; - } - if (!QDesktopServices::openUrl(qdir)) - LYXERR0("Unable to open QUrl even though dir exists!"); +{ + showDirectory(logfile_.onlyPath()); } diff --git a/src/frontends/qt/qt_helpers.cpp b/src/frontends/qt/qt_helpers.cpp index d3da0ee7de..8225b91b47 100644 --- a/src/frontends/qt/qt_helpers.cpp +++ b/src/frontends/qt/qt_helpers.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -275,6 +277,21 @@ void setSectionResizeMode(QHeaderView * view, QHeaderView::ResizeMode mode) { view->setResizeMode(mode); #endif } + +void showDirectory(FileName const & directory) +{ + if (!directory.exists()) + return; + QUrl qurl(QUrl::fromLocalFile(QDir::toNativeSeparators(toqstr(directory.absFileName())))); + // Give hints in case of bugs + if (!qurl.isValid()) { + LYXERR0("QUrl is invalid!"); + return; + + } + if (!QDesktopServices::openUrl(qurl)) + LYXERR0("Unable to open QUrl even though dir exists!"); +} } // namespace frontend QString const qt_(char const * str, const char *) diff --git a/src/frontends/qt/qt_helpers.h b/src/frontends/qt/qt_helpers.h index 92872e0808..970a02707f 100644 --- a/src/frontends/qt/qt_helpers.h +++ b/src/frontends/qt/qt_helpers.h @@ -99,6 +99,8 @@ void setSectionResizeMode(QHeaderView * view, int logicalIndex, QHeaderView::ResizeMode mode); void setSectionResizeMode(QHeaderView * view, QHeaderView::ResizeMode mode); +/// Shows a directory in OSs file browser +void showDirectory(support::FileName const & directory); } // namespace frontend diff --git a/src/frontends/qt/ui/AboutUi.ui b/src/frontends/qt/ui/AboutUi.ui index a7eecc02ec..7f38644bb0 100644 --- a/src/frontends/qt/ui/AboutUi.ui +++ b/src/frontends/qt/ui/AboutUi.ui @@ -7,7 +7,7 @@ 0 0 424 - 258 + 370 @@ -46,39 +46,140 @@ 6 - 11 + 9 - 11 + 9 - 11 + 9 - 11 + 9 - - QFrame::Box - - - QFrame::Sunken + + IBeamCursor - Version goes here + <html><head/><body><p>LyX version info goes here.</p><p>Qt version (run-time) goes here.</p><p>Qt version (compile-time) goes here.</p></body></html> Qt::AlignCenter - - 6 + + true - Qt::TextSelectableByMouse + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Library directory + + + + + + + 0 + 0 + + + + Open + + + false + + + + + + + + 0 + 0 + + + + IBeamCursor + + + Library directory goes here. + + + Qt::PlainText + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + + + User directory + + + + + + + 0 + 0 + + + + Open + + + + + + + IBeamCursor + + + User directory goes here. + + + Qt::PlainText + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + @@ -161,6 +262,21 @@ Release Notes + + 9 + + + 9 + + + 9 + + + 9 + + + 6 + @@ -185,6 +301,13 @@ 0 + + + + Copy Version Info + + +