]> git.lyx.org Git - features.git/commitdiff
simplify About dialog
authorAndré Pönitz <poenitz@gmx.net>
Wed, 5 Sep 2007 22:54:47 +0000 (22:54 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 5 Sep 2007 22:54:47 +0000 (22:54 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20088 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ControlAboutlyx.cpp [deleted file]
src/frontends/controllers/ControlAboutlyx.h [deleted file]
src/frontends/controllers/Makefile.am
src/frontends/qt4/GuiAbout.cpp
src/frontends/qt4/GuiAbout.h

diff --git a/src/frontends/controllers/ControlAboutlyx.cpp b/src/frontends/controllers/ControlAboutlyx.cpp
deleted file mode 100644 (file)
index 00d82fb..0000000
+++ /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 <config.h>
-
-#include "ControlAboutlyx.h"
-#include "gettext.h"
-#include "version.h"
-
-#include "support/filetools.h" // FileSearch
-#include "support/Package.h"
-
-#include <fstream>
-#include <sstream>
-
-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 (file)
index 7cfa322..0000000
+++ /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 <iosfwd>
-
-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
index 2e63998b10354124afc189f1d2251fa5eb1dc650..1f69abba49b6b8d86fc0b14a348c9ff023d7b6f2 100644 (file)
@@ -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 \
index 4c05af2c10dc52d2905addbc1def9c9efc746703..99cb733ddc47af6069ec86656a7dd89ea1209f75 100644 (file)
 #include <config.h>
 
 #include "GuiAbout.h"
+
 #include "qt_helpers.h"
 #include "gettext.h"
+#include "version.h"
 
-#include "support/lstrings.h"
-
-#include <sstream>
-
-#include <QLabel>
-#include <QPushButton>
-#include <QTextCodec>
-#include <QTextBrowser>
-
-using lyx::support::prefixIs;
+#include "support/filetools.h"
+#include "support/Package.h"
 
-using std::getline;
+#include <QtCore>
+#include <QtGui>
 
-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 << "<b>" << line.mid(2) << "</b>";
+                       else if (line.startsWith("@i"))
+                               out << "<i>" << line.mid(2) << "</i>";
+                       else
+                               out << line;
+                       out << "<br>";
+               } 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 << "<b>" << s.substr(2) << "</b>";
-               else if (prefixIs(s, "@i"))
-                       out << "<i>" << s.substr(2) << "</i>";
-               else
-                       out << s;
-               out << "<br>";
-       }
-#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 << "<b>" << s.substr(2) << "</b>";
-               else if (prefixIs(s, "@i"))
-                       out << "<i>" << s.substr(2) << "</i>";
-               else
-                       out << s;
-               out << "<br>";
-       }
-#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<ControlAboutlyx &>(Dialog::controller());
+       versionLA->setText(version());
+       creditsTB->setHtml(credits());
 }
 
 } // namespace frontend
index 5d1b8ccd273a4711951b1d739fade16809a52446..2567d7ca8acd94ec388079e0780b4ac3a4a05a93 100644 (file)
 #define GUIABOUT_H
 
 #include "GuiDialog.h"
-#include "ControlAboutlyx.h"
 #include "ui_AboutUi.h"
 
-#include <QDialog>
-
 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