main.cpp
3.75 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
#include "mainapp.h"
#include "mainwindow.h"
#include <Windows.h>
#include "grape/zmf.h"
#include <QTextCodec>
#include <QtDebug>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
// static QMutex mutex;
// mutex.lock();
QString text;
switch(type)
{
case QtDebugMsg:
text = QString("Debug:");
break;
case QtWarningMsg:
text = QString("Warning:");
break;
case QtCriticalMsg:
text = QString("Critical:");
break;
case QtFatalMsg:
text = QString("Fatal:");
}
QString context_info = QString("File:(%1) Line:(%2)").arg(QString(context.file)).arg(context.line);
QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss ddd");
QString current_date = QString("(%1)").arg(current_date_time);
QString message = QString("%1 %2 %3 %4").arg(text).arg(context_info).arg(msg).arg(current_date);
QFile file("log.txt");
file.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream text_stream(&file);
text_stream << message << "\r\n";
file.flush();
file.close();
// mutex.unlock();
}
MainApp::MainApp(int & argc, char ** argv) :QApplication(argc, argv)
{
}
void MainApp::notifyServiceEvent(const QString &name, size_t cookie, const Notification &info)
{
emit this->serviceEvent(name, cookie, info);
}
void MainApp::notifyAudioEvent(int eventType, const Notification &info)
{
emit this->audioEvent(eventType, info);
}
void MainApp::notifyVideoEvent(int eventType, const Notification &info)
{
emit this->videoEvent(eventType, info);
}
bool MainApp::winEventFilter(MSG * msg, long * result)
{
if (msg->message == ZmfAudioEvent)
{
Notification info = Notification::parse((const char *)msg->lParam);
notifyAudioEvent(msg->wParam, info);
}
else if (msg->message == ZmfVideoEvent)
{
Notification info = Notification::parse((const char *)msg->lParam);
notifyVideoEvent(msg->wParam, info);
}
else
return false;
*result = 0;
return true;
}
#include "login/widgetLogon.h"
#include "justtalktest.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(feitalk);
//设置编码
QTextCodec *code = QTextCodec::codecForName("GBK");
if(code == NULL)
{
code = QTextCodec::codecForLocale();
}
QTextCodec::setCodecForLocale(code);
// qInstallMessageHandler(outputMessage);
qRegisterMetaType<Notification>("IShowView");
qRegisterMetaType<Notification>("Notification");
qRegisterMetaType<Notification>("size_t");
MainApp a(argc, argv);
QFile qss(":qss/default.qss");
if(qss.open(QFile::ReadOnly))
{
QString text= qss.readAll();
qApp->setStyleSheet(text);
qss.close();
}
MainWindow window;
window.addIShow("~Default");
// window.setWindowFlags(window.windowFlags() | Qt::WindowStaysOnTopHint);
WidgetLogon *loginPage = new WidgetLogon();
loginPage->show();
loginPage->readConfig();
window.hide();
QObject::connect(loginPage, SIGNAL(loginSuccess()), &window, SLOT(show()));
QObject::connect(&window, SIGNAL(justMessage(int)), loginPage, SLOT(loginMessage(int)));
// JustTalkTest *t = new JustTalkTest();
// t->show();
QString log_name = QCoreApplication::applicationDirPath()+"/log.txt";
QFile log_file(log_name);
// qDebug("log_file.size() = %d",log_file.size());
if(log_file.exists() && log_file.size() > 1024*1024*5)
{
log_file.remove();
}
int ret = a.exec();
if (ret == 773) {
QProcess::startDetached(qApp->applicationFilePath(), QStringList());
return 0;
}
return ret;
// return a.exec();
}