Show webfinger if displayName is unknown for an author.
[larjonas-pumpa.git] / src / main.cpp
blob214744a1589d0e36fee63cd27a5d20f6f379f31f
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #include <QApplication>
21 #ifdef Q_OS_WIN32
22 #include <QStyleFactory>
23 #endif
25 #include "pumpapp.h"
26 #include "util.h"
27 #include "pumpa_defines.h"
28 #include "pumpasettings.h"
30 #include <QTranslator>
31 #include <QLocale>
33 //------------------------------------------------------------------------------
35 int testMarkup(QString str) {
36 if (str.isEmpty())
37 // str = "Hello *world*, [Some Url](http://www.foo.bar/baz). Some\n"
38 // "> block quoted text\n\n"
39 // str = "markdowned [url](http://saz.im)\n\n"
40 // "url on line http://saz.im and http://foo.bar\n"
41 // "http://saz.im\n\n"
42 // "with underlines: http://saz.im/foo_bar_baz.html ...\n"
43 // "<b>bold</b> and <i>broken html\n";
44 str = "![piktur](https://cloud.openmailbox.org/index.php/apps/files_sharing/ajax/publicpreview.php?x=1440&y=801&a=true&file=/bicinueva.JPG&t=4b267cd7510c0317681088a4b9a87588&scalingup=0)";
46 addTextMarkup(str, true);
47 return 0;
50 //------------------------------------------------------------------------------
52 int main(int argc, char** argv) {
53 QApplication app(argc, argv);
55 app.setApplicationName(CLIENT_FANCY_NAME);
56 app.setApplicationVersion(CLIENT_VERSION);
58 QString locale = QLocale::system().name();
59 #ifdef Q_OS_WIN32
60 app.setStyle(QStyleFactory::create("Fusion"));
61 #endif
63 QString settingsFile;
64 QStringList args = app.arguments();
65 if (args.count() > 1) {
66 QString arg(args[1]);
67 if (arg == "testmarkup")
68 return testMarkup(argc > 2 ? args[2] : "");
69 else if (arg == "testfeedint") {
70 qDebug() << PumpaSettingsDialog::feedIntToComboIndex(args[2].toInt());
71 return 0;
73 else if (arg == "autotestfeedint") {
74 int (*f)(int) = PumpaSettingsDialog::feedIntToComboIndex;
75 (void) f;
76 Q_ASSERT(f(0) == 0);
77 Q_ASSERT(f(1) == 0);
78 Q_ASSERT(f(2) == 1);
79 Q_ASSERT(f(3) == 0);
80 Q_ASSERT(f(4) == 0);
81 Q_ASSERT(f(5) == 0);
82 Q_ASSERT(f(6) == 2);
83 Q_ASSERT(f(11) == 0);
84 Q_ASSERT(f(12) == 0);
85 Q_ASSERT(f(14) == 3);
86 Q_ASSERT(f(15) == 4);
87 Q_ASSERT(f(16) == 0);
88 Q_ASSERT(f(255) == 0);
89 return 0;
91 else if (arg == "autotestcomboindex") {
92 int (*f)(int) = PumpaSettingsDialog::comboIndexToFeedInt;
93 (void) f;
94 Q_ASSERT(f(0) == 0);
95 Q_ASSERT(f(1) == 2);
96 Q_ASSERT(f(2) == 6);
97 Q_ASSERT(f(3) == 14);
98 Q_ASSERT(f(4) == 15);
99 Q_ASSERT(f(255) == 0);
100 return 0;
102 else if (arg == "-l" && argc == 3) {
103 locale = args[2];
104 } else if (arg == "-c" && argc == 3) {
105 settingsFile = args[2];
107 else {
108 qDebug() << "Usage: ./pumpa [-c alternative.conf] [-l locale]";
109 return 0;
113 PumpaSettings* settings =
114 PumpaSettings::getSettings(true, settingsFile, &app);
115 QString sLocale = settings->locale();
116 if (!sLocale.isEmpty())
117 locale = sLocale;
119 qDebug() << "Using locale" << locale;
121 QTranslator qtTranslator;
122 qtTranslator.load("qt_" + locale,
123 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
124 app.installTranslator(&qtTranslator);
126 QTranslator translator;
127 bool ok = translator.load(QString("pumpa_%1").arg(locale),
128 ":/translations");
129 app.installTranslator(&translator);
131 if (ok)
132 qDebug() << "Successfully loaded translation";
134 PumpApp papp(settings, locale);
135 return app.exec();