1 /************************************************************************
2 **
3 **  Copyright (C) 2009, 2010, 2011  Strahinja Markovic  <strahinja.markovic@gmail.com>
4 **
5 **  This file is part of Sigil.
6 **
7 **  Sigil is free software: you can redistribute it and/or modify
8 **  it under the terms of the GNU General Public License as published by
9 **  the Free Software Foundation, either version 3 of the License, or
10 **  (at your option) any later version.
11 **
12 **  Sigil is distributed in the hope that it will be useful,
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 **  GNU General Public License for more details.
16 **
17 **  You should have received a copy of the GNU General Public License
18 **  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
19 **
20 *************************************************************************/
21 
22 #include <QtCore/QFile>
23 #include <QRegularExpression>
24 #include <QRegularExpressionMatch>
25 
26 #include "Dialogs/About.h"
27 #include "Misc/Utility.h"
28 #include "sigil_constants.h"
29 
30 const QString VERSION_NUMBERS = "(\\d+)\\.(\\d+)\\.(\\d+)";
31 const QString SIGIL_VERSION   = QString(SIGIL_FULL_VERSION);
32 const QString SIGIL_HOMEPAGE  = "https://sigil-ebook.com/sigil";
33 const QString GNU_LICENSE     = "http://www.gnu.org/licenses/gpl-3.0-standalone.html";
34 
35 
About(QWidget * parent)36 About::About(QWidget *parent)
37     : QDialog(parent)
38 {
39     ui.setupUi(this);
40     ui.lbHomepageDisplay->setText("<a href=\"" % SIGIL_HOMEPAGE % "\">" % SIGIL_HOMEPAGE % "</a>");
41     ui.lbLicenseDisplay->setText("<a href=\"" % GNU_LICENSE % "\">" % tr("GNU General Public License v3") % "</a>");
42     ui.lbBuildTimeDisplay->setText(GetUTCBuildTime().toString("yyyy.MM.dd HH:mm:ss") + " UTC");
43     ui.lbLoadedQtDisplay->setText(QString(qVersion()));
44     QRegularExpression version_number(VERSION_NUMBERS);
45     QRegularExpressionMatch mo = version_number.match(SIGIL_VERSION);
46     QString version_text = QString("%1.%2.%3")
47                            .arg(mo.captured(1).toInt())
48                            .arg(mo.captured(2).toInt())
49                            .arg(mo.captured(3).toInt());
50     ui.lbVersionDisplay->setText(version_text);
51     QString credits = "<h4>" + tr("Maintainer(s)") + "</h4>" +
52                       "<ul>" +
53                       "<li>Kevin Hendricks</li>" +
54                       "<li>Doug Massay</li>" +
55                       "</ul>" +
56                       "<h4>" + tr("Previous Maintainer(s)") + "</h4>" +
57                       "<ul>" +
58                       "<li>John Schember</li>" +
59                       "</ul>" +
60                       "<h4>" + tr("Code Contributors") + "</h4>" +
61                       "<ul>" +
62                       "<li>Grant Drake</li>" +
63                       "<li>Dave Heiland</li>" +
64                       "<li>Charles King</li>" +
65                       "<li>Daniel Pavel</li>" +
66                       "<li>Grzegorz Wolszczak</li>" +
67                       "</ul>" +
68                       "<h4>" + tr("Translators") + "</h4>" +
69                       "<ul><li><a href=\"https://www.transifex.com/projects/p/sigil/\">https://www.transifex.com/projects/p/sigil/</a></li></ul>" +
70                       "<h4>" + tr("Original Creator") + "</h4>" +
71                       "<ul><li>Strahinja Marković  (" + tr("retired") + ")</li></ul>";
72     ui.creditsDisplay->setText(credits);
73 }
74 
75 
GetUTCBuildTime()76 QDateTime About::GetUTCBuildTime()
77 {
78     QString time_string = QString::fromLatin1(__TIME__);
79     QString date_string = QString::fromLatin1(__DATE__);
80     Q_ASSERT(!date_string.isEmpty());
81     Q_ASSERT(!time_string.isEmpty());
82     QRegularExpression date_match("(\\w{3})\\s+(\\d+)\\s+(\\d{4})");
83     QRegularExpressionMatch mo = date_match.match(date_string);
84     QDate date(mo.captured(3).toInt(), MonthIndexFromString(mo.captured(1)), mo.captured(2).toInt());
85     return QDateTime(date, QTime::fromString(time_string, "hh:mm:ss")).toUTC();
86 }
87 
88 
89 // Needed because if we use the "MMM" string in the QDate::fromString
90 // function, it will match on localized month names, not English ones.
91 // The __DATE__ macro *always* uses English month names.
MonthIndexFromString(const QString & three_letter_string)92 int About::MonthIndexFromString(const QString &three_letter_string)
93 {
94     Q_ASSERT(three_letter_string.count() == 3);
95     Q_ASSERT(three_letter_string[ 0 ].isUpper());
96 
97     if (three_letter_string == "Jan") {
98         return 1;
99     }
100 
101     if (three_letter_string == "Feb") {
102         return 2;
103     }
104 
105     if (three_letter_string == "Mar") {
106         return 3;
107     }
108 
109     if (three_letter_string == "Apr") {
110         return 4;
111     }
112 
113     if (three_letter_string == "May") {
114         return 5;
115     }
116 
117     if (three_letter_string == "Jun") {
118         return 6;
119     }
120 
121     if (three_letter_string == "Jul") {
122         return 7;
123     }
124 
125     if (three_letter_string == "Aug") {
126         return 8;
127     }
128 
129     if (three_letter_string == "Sep") {
130         return 9;
131     }
132 
133     if (three_letter_string == "Oct") {
134         return 10;
135     }
136 
137     if (three_letter_string == "Nov") {
138         return 11;
139     }
140 
141     if (three_letter_string == "Dec") {
142         return 12;
143     }
144 
145     Q_ASSERT(false);
146     return 0;
147 }
148