forked from bicomsystems/outcall2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
124 lines (103 loc) · 3.84 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
#include "OutCALL.h"
#include "Global.h"
#include "LocalServer.h"
#include "ContactManager.h"
#include "Notifier.h"
#include "Windows.h"
#include <QApplication>
#include <QMessageBox>
#include <QLocalSocket>
#include <QTranslator>
#include <QDir>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
app.setApplicationName(APP_NAME);
app.setApplicationVersion("2.0");
app.setOrganizationName(ORGANIZATION_NAME);
bool bCallRequest = false;
g_LanguagesPath = QApplication::applicationDirPath() + "/lang";
g_AppSettingsFolderPath = QDir::homePath() + "/OutCALL";
g_AppDirPath = QApplication::applicationDirPath();
if (argc==2 && QString(argv[1]) == "installer")
{
// Setup log file paths
QDir().mkpath(g_AppSettingsFolderPath);
QFile(g_AppSettingsFolderPath + "/outcall.log").remove();
if (global::IsOutlookInstalled())
{
if (global::EnableOutlookIntegration(true))
global::log("Outlook plugin installed successfully.", LOG_INFORMATION);
else
global::log("Could not install Outlook plugin.", LOG_ERROR);
}
else
{
global::log("Outlook was not detected.", LOG_INFORMATION);
}
return 0;
}
if (argc == 2)
{
bCallRequest = QString(argv[1]).contains("Dial#####");
}
if (bCallRequest)
{
QStringList arguments = QString(argv[1]).split("#####");
QString contactName = arguments[1];
QString numbers = QString(arguments[2]).replace("outcall://", "");
contactName.replace("&&&", " ");
numbers.replace("&&&", " ");
QLocalSocket s;
s.connectToServer(LOCAL_SERVER_NAME);
global::log("MAIN LOCAL", LOG_INFORMATION);
QString msg = QObject::tr("It appears that %1 is not running.\n" \
"Note for Windows 7/Vista users: please make sure that %2 and Outlook are running under same level of privileges. " \
"Either both elevated (Run as Administrator option) or non-elevated.").arg(APP_NAME).arg(APP_NAME);
if (!s.waitForConnected(2000))
{
MsgBoxInformation(msg);
}
else
{
if (!s.waitForReadyRead(2000)) // wait for "OK" from the local server
{
MsgBoxInformation(QObject::tr("Timeout on local socket. Maybe %1 is not running?").arg(APP_NAME));
}
else
{
QByteArray socket_data = QString("outlook_call %1 %2\n").arg(QString(contactName.toLatin1().toBase64())).
arg(QString(numbers.toLatin1().toBase64())).toLatin1();
s.write(socket_data);
if (!s.waitForBytesWritten(2000))
MsgBoxError(QObject::tr("Failed local socket write()."));
}
}
s.disconnectFromServer();
s.close();
return 0;
}
Notifier notifier;
QString lang = global::getSettingsValue("language", "general").toString();
QTranslator translator;
if (!lang.isEmpty())
{
if (translator.load(QString("%1/%2.lang").arg(g_LanguagesPath).arg(lang)))
{
qApp->installTranslator(&translator);
}
else
{
global::setSettingsValue("language", "", "general");
MsgBoxError(QObject::tr("Failed to load language file."));
}
}
QString username = global::getSettingsValue("username", "settings").toString();
QByteArray secret = global::getSettingsValue("password", "settings").toByteArray();
AsteriskManager manager(username, QString(QByteArray::fromBase64(secret)));
OutCall outcall;
outcall.show();
LocalServer localServer;
return app.exec();
}