-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
175 lines (143 loc) · 5.9 KB
/
main.cpp
File metadata and controls
175 lines (143 loc) · 5.9 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "menuapplications.h"
#include "utils/edir.h"
#include <QApplication>
#include "panel_adaptor.h"
//#include <QAbstractNativeEventFilter>
#include <QDBusConnection>
#include <QSettings>
void helpMe()
{
printf("Usage: elokab-terminal [OPTION]\n");
puts("elokab-terminal v: 0.3 \n" );
puts("OPTION:\n");
puts(" -h --help Print this help.\n");
puts(" -s --style <int> MenuStyle 0=classic 1=formMenu Default=0.\n");
puts(" -p, --position <int> position of menu 0= cursorPos 1=topLeft 2=topRight 3=botLeft 4=botRight\n");
puts(" -l, --layout <int> LayoutDirection 0=system 1=left-to-right 2= right-to-left\n");
puts(" -b, --browser <string> costum file manager\n");
puts(" -t, --terminal <string> costum terminal\n");
puts(" -a, --at-point <int,int> space at pos (x,y) Default=0,0\n");
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDBusConnection connection = QDBusConnection::sessionBus();
if (! QDBusConnection::sessionBus().registerService("org.elokab.qobmenu"))
{
qWarning() << "Unable to register 'org.elokab.qobmenu' service - is another instance of qobmenu running?";
QDBusInterface dbus("org.elokab.qobmenu",
"/org/elokab/qobmenu",
"org.elokab.qobmenu.Interface");
if (!dbus.isValid()) {
qDebug() << "QDBusInterface is not valid!";
return 0;
}
qDebug() << "QDBusInterface is valid!";
dbus.call("showMenu");
return 0;
}
a.setOrganizationName("elokab");
a.setApplicationName("qobmenu");
a.setApplicationDisplayName("qobmenu");
//--------------------------Arguments------------------------------------
QSettings s;
int layout=s.value("LayoutDirection",0).toInt();
QStringList args = a.arguments();
if(args.count()>1)
{
for (int i = 0; i < args.count(); ++i) {
QString arg = args.at(i);
if (arg == "-h" || arg == "--help" ) {helpMe();return 0; }
else if (arg == "-s" || arg == "--style" ) {
int style=0;
if(i+1>args.count()-1){helpMe();return 0;}
style=QString(args.at(i+1)).toInt();
if(style<0|| style>1)style=0;
s.setValue("MenuStyle",style);
}
else if (arg == "-p" || arg == "--position" ) {
int pos=0;
if(i+1>args.count()-1){helpMe();return 0;}
pos=QString(args.at(i+1)).toInt();
if(pos<0|| pos>8)pos=0;
s.setValue("MenuPos",pos);
}
else if (arg == "-l" || arg == "--layout" ) {
if(i+1>args.count()-1){helpMe();return 0;}
layout=QString(args.at(i+1)).toInt();
if(layout<0 || layout>2)layout=0;
s.setValue("LayoutDirection",layout);
}
else if (arg == "-b" || arg == "--browser" ) {
QString browser=QString();
if(i+1>args.count()-1){helpMe();return 0;}
browser=QString(args.at(i+1));
s.setValue("Browser",browser);
}
else if (arg == "-t" || arg == "--terminal" ) {
QString terminal=QString();
if(i+1>args.count()-1){helpMe();return 0;}
terminal=QString(args.at(i+1));
s.setValue("Terminal",terminal);
}
else if (arg == "-a" || arg == "--at-point" ) {
if(i+1>args.count()-1){helpMe();return 0;}
QString str=args.at(i+1);
QStringList list=str.split(",");
if(list.count()==2){
int x=QString(list.at(0)).toInt(0);
int y=QString(list.at(1)).toInt(0);
s.setValue("At-X",x);
s.setValue("At-Y",y);
}
}
}
}
//---------------------------TRANSLATION------------------------------------
/// مسار مجلد البرنامج
QString translatPath= Edir::dataDir()+"/translations";
/// جلب اعدادات اللغة
QByteArray sS=qgetenv("DESKTOP_SESSION");
QString locale;
if(sS=="elokab-session"){
QSettings globalSetting("elokab","elokabsettings");
globalSetting.beginGroup("Language");
locale=globalSetting.value("Name","Default").toString();
globalSetting.endGroup();
/// اذاكانت اللغة الافتراضية
if(locale=="Default")
locale = QLocale::system().name().section("_",0,0);
}else{
locale = QLocale::system().name().section("_",0,0);
}
/// اللغة الحالية لجميع البرنامج
QLocale::setDefault(QLocale(locale));
/// جلب ترجمات كيوتي
QString translatorFileName = QLatin1String("qt_");
translatorFileName += locale;
QTranslator *translatorsys = new QTranslator;
if (translatorsys->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
QApplication::installTranslator(translatorsys);
/// جلب ترجمة البرنامج من مجلد البرنامج
QTranslator translator;
translator.load(QString(translatPath+"/"+locale+"/"+a.applicationName()));
a.installTranslator(&translator);
QLocale lx=QLocale(locale);
switch (layout) {
case 1:
a.setLayoutDirection(Qt::LeftToRight);
break;
case 2:
a.setLayoutDirection(Qt::RightToLeft);
break;
default:
a.setLayoutDirection(lx.textDirection());
break;
}
//-------------------------------------------------------------------------------end translation
MenuApplications mp;
new panel_adaptor(&mp);
connection.registerObject("/org/elokab/qobmenu", &mp);
mp.showMenu();
return a.exec();
}