Allow to open user and library directories from About LyX.
This commit is contained in:
Daniel Ramoeller 2020-08-12 14:24:40 -04:00 committed by Richard Kimberly Heck
parent 13b928d534
commit 01b2893f8b
6 changed files with 215 additions and 51 deletions

View File

@ -11,6 +11,7 @@
#include <config.h> #include <config.h>
#include "GuiAbout.h" #include "GuiAbout.h"
#include "GuiApplication.h"
#include "ui_AboutUi.h" #include "ui_AboutUi.h"
@ -22,6 +23,7 @@
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/Package.h" #include "support/Package.h"
#include <QClipboard>
#include <QDate> #include <QDate>
#include <QFile> #include <QFile>
#include <QTextStream> #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() static QString version()
{ {
QString loc_release_date; QString loc_release_date;
@ -216,33 +245,12 @@ static QString version()
if (std::string(lyx_git_commit_hash) != "none") if (std::string(lyx_git_commit_hash) != "none")
version_date += _("Built from git commit hash ") version_date += _("Built from git commit hash ")
+ from_utf8(lyx_git_commit_hash).substr(0,8); + from_utf8(lyx_git_commit_hash).substr(0,8);
version_date += "\n";
QString res; QString res;
QTextStream out(&res); QTextStream out(&res);
out << toqstr(version_date); out << toqstr(version_date) << "\n";
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(bformat(_("Qt Version (run-time): %1$s"), from_ascii(qVersion()))) << "\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()
{
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; return res;
} }
@ -252,6 +260,24 @@ struct GuiAbout::Private
Ui::AboutUi ui; 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) GuiAbout::GuiAbout(GuiView & lv)
: DialogView(lv, "aboutlyx", qt_("About LyX")), : DialogView(lv, "aboutlyx", qt_("About LyX")),
@ -259,6 +285,9 @@ GuiAbout::GuiAbout(GuiView & lv)
{ {
d->ui.setupUi(this); d->ui.setupUi(this);
// fix height to minimum
setFixedHeight(sizeHint().height());
d->ui.copyrightTB->setPlainText(copyright()); d->ui.copyrightTB->setPlainText(copyright());
d->ui.copyrightTB->append(QString()); d->ui.copyrightTB->append(QString());
d->ui.copyrightTB->append(license()); d->ui.copyrightTB->append(license());
@ -266,6 +295,8 @@ GuiAbout::GuiAbout(GuiView & lv)
d->ui.copyrightTB->append(disclaimer()); d->ui.copyrightTB->append(disclaimer());
d->ui.versionLA->setText(version()); d->ui.versionLA->setText(version());
d->ui.dirLibraryLA->setText(dirLibrary());
d->ui.dirUserLA->setText(dirUser());
d->ui.buildinfoTB->setText(buildinfo()); d->ui.buildinfoTB->setText(buildinfo());
d->ui.releasenotesTB->setHtml(release_notes()); d->ui.releasenotesTB->setHtml(release_notes());
d->ui.releasenotesTB->setOpenExternalLinks(true); d->ui.releasenotesTB->setOpenExternalLinks(true);

View File

@ -27,6 +27,9 @@ public:
private Q_SLOTS: private Q_SLOTS:
void on_buttonBox_rejected(); void on_buttonBox_rejected();
void on_showDirLibraryPB_clicked();
void on_showDirUserPB_clicked();
void on_versionCopyPB_clicked();
private: private:
/// Controller stuff /// Controller stuff

View File

@ -25,10 +25,8 @@
#include "support/gettext.h" #include "support/gettext.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include <QDesktopServices>
#include <QTextBrowser> #include <QTextBrowser>
#include <QSyntaxHighlighter> #include <QSyntaxHighlighter>
#include <QUrl>
#include <QClipboard> #include <QClipboard>
#include <fstream> #include <fstream>
@ -192,17 +190,7 @@ void GuiLog::on_nextWarningPB_clicked()
void GuiLog::on_openDirPB_clicked() void GuiLog::on_openDirPB_clicked()
{ {
support::FileName dir = logfile_.onlyPath(); showDirectory(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!");
} }

View File

@ -38,6 +38,8 @@
#include <QApplication> #include <QApplication>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QDesktopServices>
#include <QDir>
#include <QLineEdit> #include <QLineEdit>
#include <QLocale> #include <QLocale>
#include <QPalette> #include <QPalette>
@ -275,6 +277,21 @@ void setSectionResizeMode(QHeaderView * view, QHeaderView::ResizeMode mode) {
view->setResizeMode(mode); view->setResizeMode(mode);
#endif #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 } // namespace frontend
QString const qt_(char const * str, const char *) QString const qt_(char const * str, const char *)

View File

@ -99,6 +99,8 @@ void setSectionResizeMode(QHeaderView * view,
int logicalIndex, QHeaderView::ResizeMode mode); int logicalIndex, QHeaderView::ResizeMode mode);
void setSectionResizeMode(QHeaderView * view, void setSectionResizeMode(QHeaderView * view,
QHeaderView::ResizeMode mode); QHeaderView::ResizeMode mode);
/// Shows a directory in OSs file browser
void showDirectory(support::FileName const & directory);
} // namespace frontend } // namespace frontend

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>424</width> <width>424</width>
<height>258</height> <height>370</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -46,39 +46,140 @@
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>11</number> <number>9</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>11</number> <number>9</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>11</number> <number>9</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>11</number> <number>9</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="versionLA"> <widget class="QLabel" name="versionLA">
<property name="frameShape"> <property name="cursor">
<enum>QFrame::Box</enum> <cursorShape>IBeamCursor</cursorShape>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property> </property>
<property name="text"> <property name="text">
<string>Version goes here</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;LyX version info goes here.&lt;/p&gt;&lt;p&gt;Qt version (run-time) goes here.&lt;/p&gt;&lt;p&gt;Qt version (compile-time) goes here.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
<property name="margin"> <property name="wordWrap">
<number>6</number> <bool>true</bool>
</property> </property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<widget class="QWidget" name="creditstab"> <widget class="QWidget" name="creditstab">
@ -161,6 +262,21 @@
<string>Release Notes</string> <string>Release Notes</string>
</attribute> </attribute>
<layout class="QGridLayout"> <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"> <item row="0" column="0">
<widget class="QTextBrowser" name="releasenotesTB"/> <widget class="QTextBrowser" name="releasenotesTB"/>
</item> </item>
@ -185,6 +301,13 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item>
<widget class="QPushButton" name="versionCopyPB">
<property name="text">
<string>Copy Version Info</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons"> <property name="standardButtons">