-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
126 lines (109 loc) · 3.33 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* desktop-file-memos: A desktop classification app on Linux.
*
* Copyright (C) 2019, Tianjin KYLIN Information Technology Co., Ltd.
*
* 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 3 of the License, or
* any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Yue Lan<[email protected]>
*
*/
#include <QApplication>
#include <QSettings>
#include <QMainWindow>
#include "iconview.h"
#include "splitter.h"
#include "systemtrayicon.h"
#include "settingshelper.h"
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <QSplitter>
#include <QDebug>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
#define LOCKFILE "/tmp/.desktopfilememos.pid"
#define LOCKMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
static void viewInit();
int lockfile(int fd) {
struct flock fl;
fl.l_type = F_WRLCK;
fl.l_start = 0;
fl.l_whence = SEEK_SET;
fl.l_len = 0;
return(fcntl(fd, F_SETLK, &fl));
}
int already_running(const char *filename) {
int fd;
fd = open(filename, O_RDWR | O_CREAT, LOCKMODE);
if (lockfile(fd) == -1) {
if (errno == EACCES || errno == EAGAIN) {
close(fd);
return 1;
}
}
return 0;
}
int main(int argc, char *argv[]) {
argc = 3;
argv[1] = strdup("-platformtheme");
argv[2] = strdup("gtk3");
/*
qDebug()<<argc;
for (int i = 0; i < argc; i++) {
qDebug()<<argv[i];
}
*/
QApplication a(argc, argv);
a.setOrganizationName("com.kylin");
a.setApplicationName("desktopfilememos");
qDebug()<<a.organizationName();
qDebug()<<a.applicationName();
if (already_running(LOCKFILE)) {
qDebug()<<"isRunning!";
exit(1);
}
viewInit();
SystemTrayIcon *tray = new SystemTrayIcon;
tray->show();
return a.exec();
}
void viewInit() {
SettingsHelper *settingsHelper = new SettingsHelper;
QSettings *settings = settingsHelper->getSettings();
settingsHelper->getSettings()->beginGroup("iconview/id_count");
int idCout = settingsHelper->getSettings()->value("lastid").toInt();
settings->endGroup();
qDebug()<<idCout<<endl;
for (int i = 1; i <= idCout; i++) {
settings->beginGroup("iconview/id_title_table");
QString title_for_this_id = settings->value(QString(i)).toString();
//qDebug()<<settings->value(QString(i));
qDebug()<<"id: "<<i<<", title: "<<title_for_this_id;
settings->endGroup();
settings->beginGroup("iconview/id_state_table");
int state = settings->value(QString(i)).toInt();
settings->endGroup();
//qDebug()<<settings->value(QString(i));
if (state == 1) {
Splitter *page = new Splitter(i, title_for_this_id);
page->show();
page->ensureLastSettings(settings);
}
}
delete settingsHelper;
}