Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
138 lines (114 loc) · 3.34 KB
/
Copy pathmain.cpp
File metadata and controls
138 lines (114 loc) · 3.34 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
/**
* ZenShot - Open-source cross-platform screenshot tool.
*
* @copyright Copyright 2009-2025 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.chandao.com)
* @license LGPL v3.0 - Full terms in LICENSE file.
* @notice This program uses Qt which is licensed under LGPL v3.
*/
#ifdef __unix__
#include <gtk/gtk.h>
#endif // __unix__
#include <QApplication>
#include <QTranslator>
#include <QLocale>
#include <QMetaEnum>
#include <QFile>
#include <QList>
#include <QFontDatabase>
#include <QWidget>
#include "spdlogwrapper.hpp"
#include "widget.h"
#include "starterui.h"
#include "starter.h"
#include "core/screeninfo.h"
#include "screen/helper/screengetter.h"
#include "core/gparams.h"
#include <QDir>
#include <QLockFile>
#include <QCommandLineParser>
#include <QCommandLineOption>
#ifdef Q_OS_WIN
#include <direct.h>
#else
#include <sys/stat.h>
#include <sys/types.h>
#endif // Q_OS_WIN
#ifdef IS_XUANXUAN_VER_
static const char mutex_name[] = "zenshot.zentao.xx";
#else
static const char mutex_name[] = "zenshot.zentao";
#endif // IS_XUANXUAN_VER_
int main(int argc, char *argv[])
{
#ifdef USE_SPDLOG_
#ifdef Q_OS_WIN
mkdir("logs");
#else
mkdir("logs", S_IRWXU);
#endif // Q_OS_WIN
spdlog::spdlog_init("zenshot", "logs/log.log", 23, 57, 1, 1);
L_TRACE("start");
#endif // USE_SPDLOG_
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
QApplication a(argc, argv);
QLocalSocket local_sock;
QLocalServer local_server;
local_sock.connectToServer(mutex_name);
if (local_sock.waitForConnected(800))
{
local_sock.disconnectFromServer();
local_sock.close();
L_TRACE("already running ...");
return 0;
}
QLocalServer::removeServer(mutex_name);
if (!local_server.listen(mutex_name))
{
L_TRACE("local_server listen {0} failed ...", mutex_name);
return 0;
}
// QString full_name = QDir::temp().absoluteFilePath(mutex_name);
// L_TRACE(full_name.toStdString().c_str());
// QLockFile file(full_name);
// if (!file.tryLock())
// {
// L_TRACE("already running ...");
// return 0;
// }
#ifdef Q_OS_UNIX
gdk_init(NULL, NULL);
#endif // Q_OS_LINUX
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
L_ERROR("system tray disabled");
return 1;
}
//加载并应用语言翻译界面
QLocale locale;
QLocale::Language langEnum = locale.language();
QMetaEnum metaEnum = QMetaEnum::fromType<QLocale::Language>();
const char* langChar = metaEnum.valueToKey(langEnum);
QString langName(langChar);
QString langFile = ":/translations/" + langName + ".qm";
if(QFile(langFile).exists() == false)
{
langFile = ":/translations/English.qm";
}
QTranslator translator;
translator.load(langFile);
a.installTranslator(&translator);
//加载图标字体文件
int fontId = QFontDatabase::addApplicationFont(":/iconfont.ttf");
QString fontNmae = QFontDatabase::applicationFontFamilies(fontId).at(0);
//设置系统默认字体
QFont defaultFont("微软雅黑",9);
a.setFont(defaultFont);
//解析命令行参数
int result = GParams::instance()->fromArgs(argc,argv);
if(result != 0)
return result;
a.setQuitOnLastWindowClosed(false);
StarterUI ui(&local_server);
ui.show();
int ret = a.exec();
return ret;
}