cleanup
[fapman] / main.cpp
1 /*
2         This file is part of Faster Application Manager.
3
4         Faster Application Manager is free software: you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation, either version 3 of the License, or
7         (at your option) any later version.
8
9         Faster Application Manager is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with Faster Application Manager.  If not, see <http://www.gnu.org/licenses/>.
16
17         (C) Heikki Holstila 2010
18 */
19
20 #include <QtGui/QApplication>
21 #include <QtDBus>
22 #include <iostream>
23 #include "mainwindow.h"
24 #include "confirmdialog.h"
25
26 #include <unistd.h>
27 #include <sys/vfs.h>
28
29 bool EnableDebugOutput = false;
30
31 void myMessageOutput( QtMsgType, const char *msg )
32 {
33         if( EnableDebugOutput )
34                 std::cerr << msg << std::endl;
35 }
36
37 int main(int argc, char *argv[])
38 {
39         qInstallMsgHandler( myMessageOutput );
40     QApplication a(argc, argv);
41
42         a.setApplicationName("faster_application_manager");
43         QDir::setCurrent("/root/.fapman/");
44
45         EnableDebugOutput = false;
46         if( a.arguments().contains("-d") ) {
47                 EnableDebugOutput = true;
48                 qDebug() << "Enabled debug output";
49         }
50
51         MainWindow w;
52
53 #if defined(Q_WS_S60)
54     w.showMaximized();
55 #else
56     w.show();
57 #endif
58
59 #ifdef Q_WS_MAEMO_5
60         uid_t userUID = getuid();
61         if( userUID != 0 ) {
62                 ConfirmDialog d(false, &w);
63                 d.setText("Warning", "You are not running the application as root. It won't work as intended.");
64                 d.exec();
65         }
66
67         quint64 warn_limit_root = 5120;
68         quint64 warn_limit_opt = 51200;
69         struct statfs root_stat;
70         struct statfs opt_stat;
71         statfs("/",&root_stat);
72         statfs("/opt",&opt_stat);
73         quint64 free_root = root_stat.f_bavail * root_stat.f_bsize / 1024;
74         quint64 free_opt = opt_stat.f_bavail * opt_stat.f_bsize / 1024;
75         qDebug() << "rootfs" << free_root << "kB free";
76         qDebug() << "opt fs" << free_opt << "kB free";
77         if( free_root < warn_limit_root || free_opt < warn_limit_opt )
78         {
79                 ConfirmDialog d(false, &w);
80                 QString t;
81                 if( free_root < warn_limit_root )
82                         t += QString("Root filesystem has %L1 kB available<br>").arg(free_root);
83                 if( free_opt < warn_limit_opt )
84                         t += QString("Opt (home) filesystem has %L1 kB available<br>").arg(free_opt);
85                 t += "<br>You may proceed, but consider freeing up space to prevent problems in the future";
86                 d.setText("Warning: Low disk space",t);
87                 d.exec();
88         }
89
90         // *** from patch by qwerty12 ***
91         if (!QDBusConnection::sessionBus().isConnected()) {
92                 qWarning("Cannot connect to the D-Bus session bus.");
93         }
94
95         if (!QDBusConnection::sessionBus().registerService("org.maemo.faster_application_manager")) {
96                 qWarning("%s", qPrintable(QDBusConnection::sessionBus().lastError().message()));
97         }
98         
99         if (!QDBusConnection::sessionBus().registerObject("/org/maemo/faster_application_manager", &w, QDBusConnection::ExportScriptableSlots)) {
100                 qWarning("%s", qPrintable(QDBusConnection::sessionBus().lastError().message()));
101         }
102         // ***
103
104 #endif
105
106     return a.exec();
107 }
108