1 /*
2 This file is part of Android File Transfer For Linux.
3 Copyright (C) 2015-2020 Vladimir Menshakov
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License,
8 or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include "mainwindow.h"
21 #include "utils.h"
22 #include <QApplication>
23 #include <QLibraryInfo>
24 #include <QLocale>
25 #include <QMessageBox>
26 #include <QTranslator>
27 #include <mtp/log.h>
28 #if QT_VERSION >= 0x050000
29 # include <QGuiApplication>
30 #endif
31
32 namespace
33 {
34 class Application : public QApplication
35 {
36 public:
Application(int & argc,char ** argv,int flags=ApplicationFlags)37 Application(int &argc, char **argv, int flags = ApplicationFlags):
38 QApplication(argc, argv, flags)
39 { }
40
notify(QObject * receiver,QEvent * e)41 virtual bool notify ( QObject * receiver, QEvent * e )
42 {
43 try {
44 return QApplication::notify( receiver, e );
45 } catch ( const std::exception& e ) {
46 QMessageBox::warning(0, "Error", fromUtf8(e.what()));
47 return false;
48 }
49 }
50 };
51 }
52
main(int argc,char * argv[])53 int main(int argc, char *argv[])
54 {
55 QApplication app(argc, argv);
56 Q_INIT_RESOURCE(android_file_transfer);
57
58 QCoreApplication::setApplicationName("aft-linux-qt");
59 QCoreApplication::setOrganizationDomain("whoozle.github.io");
60 QCoreApplication::setOrganizationName("whoozle.github.io");
61
62 #if QT_VERSION >= 0x050000
63 QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
64 #endif
65
66 QTranslator qtTranslator;
67
68 qtTranslator.load("qt_" + QLocale::system().name(),
69 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
70 app.installTranslator(&qtTranslator);
71
72 QTranslator aTranslator;
73 aTranslator.load(":/android-file-transfer-linux_" + QLocale::system().name());
74 app.installTranslator(&aTranslator);
75
76 MainWindow w;
77
78 for (int i = 0; i < argc; ++i) {
79 if (strcmp(argv[i], "-R") == 0)
80 w.enableDeviceReset(true);
81 else if (strcmp(argv[i], "-v") == 0)
82 mtp::g_debug = true;
83 }
84
85 w.show();
86
87 if (!w.started())
88 return 1;
89
90 return app.exec();
91 }
92