From 665119e4f6455fe951adc039c9f77db434ed5d5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 5 Sep 2007 22:54:47 +0000 Subject: [PATCH] simplify About dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20088 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ControlAboutlyx.cpp | 102 ----------- src/frontends/controllers/ControlAboutlyx.h | 49 ----- src/frontends/controllers/Makefile.am | 2 - src/frontends/qt4/GuiAbout.cpp | 168 +++++++++--------- src/frontends/qt4/GuiAbout.h | 5 - 5 files changed, 86 insertions(+), 240 deletions(-) delete mode 100644 src/frontends/controllers/ControlAboutlyx.cpp delete mode 100644 src/frontends/controllers/ControlAboutlyx.h diff --git a/src/frontends/controllers/ControlAboutlyx.cpp b/src/frontends/controllers/ControlAboutlyx.cpp deleted file mode 100644 index 00d82fbf6c..0000000000 --- a/src/frontends/controllers/ControlAboutlyx.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/** - * \file ControlAboutlyx.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Edwin Leuven - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "ControlAboutlyx.h" -#include "gettext.h" -#include "version.h" - -#include "support/filetools.h" // FileSearch -#include "support/Package.h" - -#include -#include - -using std::ostream; -using std::ostringstream; -using std::string; - - -namespace lyx { - -using support::FileName; -using support::fileSearch; -using support::makeDisplayPath; -using support::package; - -namespace frontend { - - -ControlAboutlyx::ControlAboutlyx(Dialog & parent) - : Dialog::Controller(parent) -{} - - -void ControlAboutlyx::getCredits(ostream & ss) const -{ - FileName const name = fileSearch(package().system_support().absFilename(), "CREDITS"); - - bool found(!name.empty()); - - if (found) { - std::ifstream in(name.toFilesystemEncoding().c_str()); - - ss << in.rdbuf(); - found = ss.good(); - } - - if (!found) { - ss << to_utf8(_("ERROR: LyX wasn't able to read CREDITS file\n")) - << to_utf8(_("Please install correctly to estimate the great\n")) - << to_utf8(_("amount of work other people have done for the LyX project.")); - } -} - - -string const ControlAboutlyx::getCopyright() const -{ - return to_utf8(_("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995-2006 LyX Team")); -} - - -string const ControlAboutlyx::getLicense() const -{ - return to_utf8(_("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 (at your option) any later version.")); -} - - -string const ControlAboutlyx::getDisclaimer() const -{ - return to_utf8(_("LyX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\nSee the GNU General Public License for more details.\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.")); -} - - -string const ControlAboutlyx::getVersion() const -{ - ostringstream ss; - - ss << to_utf8(_("LyX Version ")) - << lyx_version - << " (" - << lyx_release_date - << ")\n" - << to_utf8(_("Library directory: ")) - << to_utf8(makeDisplayPath(package().system_support().absFilename())) - << "\n" - << to_utf8(_("User directory: ")) - << to_utf8(makeDisplayPath(package().user_support().absFilename())); - - return ss.str(); -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/controllers/ControlAboutlyx.h b/src/frontends/controllers/ControlAboutlyx.h deleted file mode 100644 index 7cfa322b3a..0000000000 --- a/src/frontends/controllers/ControlAboutlyx.h +++ /dev/null @@ -1,49 +0,0 @@ -// -*- C++ -*- -/** - * \file ControlAboutlyx.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Edwin Leuven - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef CONTROLABOUTLYX_H -#define CONTROLABOUTLYX_H - -#include "Dialog.h" -#include - -namespace lyx { -namespace frontend { - -/** \c ControlAboutlyx is a controller for the "About LyX" dialogs. - */ -class ControlAboutlyx : public Dialog::Controller { -public: - ControlAboutlyx(Dialog & parent); - - //@{ - /// Instantiate Dialog::Controller methods. - virtual bool initialiseParams(std::string const &) { return true; } - virtual void clearParams() {} - virtual void dispatchParams() {} - virtual bool isBufferDependent() const { return false; } - //@} - - //@{ - /// Provide the View with specific pieces of information. - void getCredits(std::ostream &) const; - std::string const getCopyright() const; - std::string const getLicense() const; - std::string const getDisclaimer() const; - std::string const getVersion() const; - //@} -}; - -} // namespace frontend -} // namespace lyx - -#endif // CONTROLABOUTLYX_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 2e63998b10..1f69abba49 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -11,7 +11,6 @@ SOURCEFILES = \ Dialog.cpp \ Kernel.cpp \ ButtonPolicy.cpp \ - ControlAboutlyx.cpp \ ControlBibtex.cpp \ ControlBox.cpp \ ControlBranch.cpp \ @@ -53,7 +52,6 @@ SOURCEFILES = \ HEADERFILES = \ Kernel.h \ ButtonPolicy.h \ - ControlAboutlyx.h \ ControlBibtex.h \ ControlBox.h \ ControlBranch.h \ diff --git a/src/frontends/qt4/GuiAbout.cpp b/src/frontends/qt4/GuiAbout.cpp index 4c05af2c10..99cb733ddc 100644 --- a/src/frontends/qt4/GuiAbout.cpp +++ b/src/frontends/qt4/GuiAbout.cpp @@ -11,114 +11,118 @@ #include #include "GuiAbout.h" + #include "qt_helpers.h" #include "gettext.h" +#include "version.h" -#include "support/lstrings.h" - -#include - -#include -#include -#include -#include - -using lyx::support::prefixIs; +#include "support/filetools.h" +#include "support/Package.h" -using std::getline; +#include +#include -using std::istringstream; -using std::ostringstream; -using std::string; +using lyx::support::package; +using lyx::support::makeDisplayPath; namespace lyx { namespace frontend { -GuiAboutDialog::GuiAboutDialog(LyXView & lv) - : GuiDialog(lv, "aboutlyx") +static QString credits() { - setupUi(this); - setViewTitle(_("About LyX")); + QString res; + QFile file(toqstr(package().system_support().absFilename()) + "CREDITS"); + QTextStream out(&res); + + if (file.isReadable()) { + out << toqstr(_("ERROR: LyX wasn't able to read CREDITS file\n")); + out << toqstr(_("Please install correctly to estimate the great\n")); + out << toqstr(_("amount of work other people have done for the LyX project.")); + } else { + file.open(QIODevice::ReadOnly); + QTextStream ts(&file); + QString line; + do { + line = ts.readLine(); + if (line.startsWith("@b")) + out << "" << line.mid(2) << ""; + else if (line.startsWith("@i")) + out << "" << line.mid(2) << ""; + else + out << line; + out << "
"; + } while (!line.isNull()); + } + out.flush(); + return res; +} - setController(new ControlAboutlyx(*this)); - connect(closePB, SIGNAL(clicked()), this, SLOT(reject())); +static QString copyright() +{ + return toqstr(_("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995-2006 LyX Team")); +} - connect(closePB, SIGNAL(clicked()), - this, SLOT(slotClose())); - copyrightTB->setPlainText(toqstr(controller().getCopyright())); - copyrightTB->append(""); - copyrightTB->append(toqstr(controller().getLicense())); - copyrightTB->append(""); - copyrightTB->append(toqstr(controller().getDisclaimer())); +static QString license() +{ + return toqstr(_("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 (at your option) any later version.")); +} - versionLA->setText(toqstr(controller().getVersion())); - // The code below should depend on a autoconf test. (Lgb) -#if 1 - // There are a lot of buggy stringstream implementations..., but the - // code below will work on all of them (I hope). The drawback with - // this solutions os the extra copying. (Lgb) +static QString disclaimer() +{ + return toqstr(_("LyX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\nSee the GNU General Public License for more details.\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.")); +} - ostringstream in; - controller().getCredits(in); - istringstream ss(in.str()); +static QString version() +{ + QString res; + QTextStream out(&res); + out << toqstr(_("LyX Version ")); + out << lyx_version; + out << " ("; + out << lyx_release_date; + out << ")\n"; + out << toqstr(_("Library directory: ")); + out << toqstr(makeDisplayPath(package().system_support().absFilename())); + out << "\n"; + out << toqstr(_("User directory: ")); + out << toqstr(makeDisplayPath(package().user_support().absFilename())); + return res; +} - string s; - ostringstream out; - while (getline(ss, s)) { - if (prefixIs(s, "@b")) - out << "" << s.substr(2) << ""; - else if (prefixIs(s, "@i")) - out << "" << s.substr(2) << ""; - else - out << s; - out << "
"; - } -#else - // Good stringstream implementations can handle this. It avoids - // some copying, and should thus be faster and use less memory. (Lgb) - // I'll make this the default for a short while to see if anyone - // see the error... - stringstream in; - controller().getCredits(in); - in.seekg(0); - string s; - ostringstream out; - - while (getline(in, s)) { - if (prefixIs(s, "@b")) - out << "" << s.substr(2) << ""; - else if (prefixIs(s, "@i")) - out << "" << s.substr(2) << ""; - else - out << s; - out << "
"; - } -#endif +class ControlAbout : public Dialog::Controller +{ +public: + ControlAbout(Dialog & parent) : Dialog::Controller(parent) {} + bool initialiseParams(std::string const &) { return true; } + void clearParams() {} + void dispatchParams() {} + bool isBufferDependent() const { return false; } +}; - creditsTB->setHtml(toqstr(out.str())); - // try to resize to a good size - copyrightTB->hide(); - setMinimumSize(copyrightTB->sizeHint()); - copyrightTB->show(); - setMinimumSize(sizeHint()); +GuiAboutDialog::GuiAboutDialog(LyXView & lv) + : GuiDialog(lv, "aboutlyx") +{ + setupUi(this); + setViewTitle(_("About LyX")); + setController(new ControlAbout(*this)); - // Manage the cancel/close button - bc().setPolicy(ButtonPolicy::OkCancelPolicy); - bc().setCancel(closePB); - bc().refresh(); -} + connect(closePB, SIGNAL(clicked()), this, SLOT(reject())); + copyrightTB->setPlainText(copyright()); + copyrightTB->append(QString()); + copyrightTB->append(license()); + copyrightTB->append(QString()); + copyrightTB->append(disclaimer()); -ControlAboutlyx & GuiAboutDialog::controller() const -{ - return static_cast(Dialog::controller()); + versionLA->setText(version()); + creditsTB->setHtml(credits()); } } // namespace frontend diff --git a/src/frontends/qt4/GuiAbout.h b/src/frontends/qt4/GuiAbout.h index 5d1b8ccd27..2567d7ca8a 100644 --- a/src/frontends/qt4/GuiAbout.h +++ b/src/frontends/qt4/GuiAbout.h @@ -13,11 +13,8 @@ #define GUIABOUT_H #include "GuiDialog.h" -#include "ControlAboutlyx.h" #include "ui_AboutUi.h" -#include - namespace lyx { namespace frontend { @@ -28,8 +25,6 @@ class GuiAboutDialog : public GuiDialog, public Ui::AboutUi public: // Constructor GuiAboutDialog(LyXView & lv); - /// parent controller - ControlAboutlyx & controller() const; }; } // namespace frontend -- 2.39.2