[LyX/master] Fix bug #10346.

Richard Kimberly Heck rikiheck at lyx.org
Wed Aug 12 18:00:08 UTC 2020


commit 01b2893f8beef6a9716195ee5e7b42c75e135fae
Author: Daniel Ramoeller <d.lyx at web.de>
Date:   Wed Aug 12 14:24:40 2020 -0400

    Fix bug #10346.
    
    Allow to open user and library directories from About LyX.
---
 src/frontends/qt/GuiAbout.cpp   |   75 ++++++++++++++------
 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, 214 insertions(+), 50 deletions(-)

diff --git a/src/frontends/qt/GuiAbout.cpp b/src/frontends/qt/GuiAbout.cpp
index a641e9a..25c3a68 100644
--- a/src/frontends/qt/GuiAbout.cpp
+++ b/src/frontends/qt/GuiAbout.cpp
@@ -11,6 +11,7 @@
 #include <config.h>
 
 #include "GuiAbout.h"
+#include "GuiApplication.h"
 
 #include "ui_AboutUi.h"
 
@@ -22,6 +23,7 @@
 #include "support/lstrings.h"
 #include "support/Package.h"
 
+#include <QClipboard>
 #include <QDate>
 #include <QFile>
 #include <QTextStream>
@@ -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,41 +245,38 @@ 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";
+	out << toqstr(bformat(_("Qt Version (compile-time): %1$s"), from_ascii(QT_VERSION_STR)));
 	return res;
 }
 
-static QString buildinfo()
+
+struct GuiAbout::Private
 {
-	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;
+	Ui::AboutUi ui;
+};
 
-	out << lyx_version_info << endl;
-	return res;
+void GuiAbout::on_showDirLibraryPB_clicked()
+{
+	showDirectory(package().system_support());
 }
 
 
-struct GuiAbout::Private
+void GuiAbout::on_showDirUserPB_clicked()
 {
-	Ui::AboutUi ui;
-};
+	showDirectory(package().user_support());
+}
+
+
+void GuiAbout::on_versionCopyPB_clicked()
+{
+	QClipboard *clipboard = QGuiApplication::clipboard();
+	clipboard->setText(version());
+}
 
 
 GuiAbout::GuiAbout(GuiView & lv)
@@ -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 200f0b7..acd485f 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 341f06c..8682806 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 <QDesktopServices>
 #include <QTextBrowser>
 #include <QSyntaxHighlighter>
-#include <QUrl>
 #include <QClipboard>
 
 #include <fstream>
@@ -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 d3da0ee..8225b91 100644
--- a/src/frontends/qt/qt_helpers.cpp
+++ b/src/frontends/qt/qt_helpers.cpp
@@ -38,6 +38,8 @@
 #include <QApplication>
 #include <QCheckBox>
 #include <QComboBox>
+#include <QDesktopServices>
+#include <QDir>
 #include <QLineEdit>
 #include <QLocale>
 #include <QPalette>
@@ -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 92872e0..970a027 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 a7eecc0..7f38644 100644
--- a/src/frontends/qt/ui/AboutUi.ui
+++ b/src/frontends/qt/ui/AboutUi.ui
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>424</width>
-    <height>258</height>
+    <height>370</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -46,37 +46,138 @@
         <number>6</number>
        </property>
        <property name="leftMargin">
-        <number>11</number>
+        <number>9</number>
        </property>
        <property name="topMargin">
-        <number>11</number>
+        <number>9</number>
        </property>
        <property name="rightMargin">
-        <number>11</number>
+        <number>9</number>
        </property>
        <property name="bottomMargin">
-        <number>11</number>
+        <number>9</number>
        </property>
        <item>
         <widget class="QLabel" name="versionLA">
-         <property name="frameShape">
-          <enum>QFrame::Box</enum>
-         </property>
-         <property name="frameShadow">
-          <enum>QFrame::Sunken</enum>
+         <property name="cursor">
+          <cursorShape>IBeamCursor</cursorShape>
          </property>
          <property name="text">
-          <string>Version goes here</string>
+          <string><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></string>
          </property>
          <property name="alignment">
           <set>Qt::AlignCenter</set>
          </property>
-         <property name="margin">
-          <number>6</number>
+         <property name="wordWrap">
+          <bool>true</bool>
          </property>
          <property name="textInteractionFlags">
-          <set>Qt::TextSelectableByMouse</set>
+          <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="verticalSpacer">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
          </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="gridGroupBox">
+         <property name="title">
+          <string>Library directory</string>
+         </property>
+         <layout class="QGridLayout" name="gridLayout_3">
+          <item row="0" column="1">
+           <widget class="QPushButton" name="showDirUserPB">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="text">
+             <string>Open</string>
+            </property>
+            <property name="flat">
+             <bool>false</bool>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="0">
+           <widget class="QLabel" name="dirLibraryLA">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="cursor">
+             <cursorShape>IBeamCursor</cursorShape>
+            </property>
+            <property name="text">
+             <string>Library directory goes here.</string>
+            </property>
+            <property name="textFormat">
+             <enum>Qt::PlainText</enum>
+            </property>
+            <property name="wordWrap">
+             <bool>true</bool>
+            </property>
+            <property name="textInteractionFlags">
+             <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="gridGroupBox1">
+         <property name="title">
+          <string>User directory</string>
+         </property>
+         <layout class="QGridLayout" name="gridLayout_4">
+          <item row="0" column="1">
+           <widget class="QPushButton" name="showDirLibraryPB">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="text">
+             <string>Open</string>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="0">
+           <widget class="QLabel" name="dirUserLA">
+            <property name="cursor">
+             <cursorShape>IBeamCursor</cursorShape>
+            </property>
+            <property name="text">
+             <string>User directory goes here.</string>
+            </property>
+            <property name="textFormat">
+             <enum>Qt::PlainText</enum>
+            </property>
+            <property name="wordWrap">
+             <bool>true</bool>
+            </property>
+            <property name="textInteractionFlags">
+             <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
+            </property>
+           </widget>
+          </item>
+         </layout>
         </widget>
        </item>
       </layout>
@@ -161,6 +262,21 @@
        <string>Release Notes</string>
       </attribute>
       <layout class="QGridLayout">
+       <property name="leftMargin">
+        <number>9</number>
+       </property>
+       <property name="topMargin">
+        <number>9</number>
+       </property>
+       <property name="rightMargin">
+        <number>9</number>
+       </property>
+       <property name="bottomMargin">
+        <number>9</number>
+       </property>
+       <property name="spacing">
+        <number>6</number>
+       </property>
        <item row="0" column="0">
         <widget class="QTextBrowser" name="releasenotesTB"/>
        </item>
@@ -186,6 +302,13 @@
       <number>0</number>
      </property>
      <item>
+      <widget class="QPushButton" name="versionCopyPB">
+       <property name="text">
+        <string>Copy Version Info</string>
+       </property>
+      </widget>
+     </item>
+     <item>
       <widget class="QDialogButtonBox" name="buttonBox">
        <property name="standardButtons">
         <set>QDialogButtonBox::Close</set>


More information about the lyx-cvs mailing list