~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to mainui/mainwindow.cpp

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 ~ 2015 National University of Defense Technology(NUDT) & Kylin Ltd.
3
 
 *
4
 
 * Authors:
5
 
 *  Kobe Lee    xiangli@ubuntukylin.com/kobe24_lixiang@126.com
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; version 3.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include "mainwindow.h"
21
 
#include <QDebug>
22
 
#include <QPropertyAnimation>
23
 
#include <QParallelAnimationGroup>
24
 
#include "shadowwidget.h"
25
 
//#include "cameramanager.h"
26
 
#include "../component/threadpool.h"
27
 
 
28
 
QString GlobalData::globalarch = ""; // add by hebing, just for transmit var
29
 
 
30
 
MainWindow::MainWindow(QString cur_arch, int d_count, QWidget *parent) :
31
 
    QDialog(parent), arch(cur_arch), display_count(d_count)/*skin_center(parent),*/
32
 
{
33
 
 
34
 
    GlobalData::globalarch = this->arch;
35
 
 
36
 
    this->osName = accessOSName();
37
 
//    char *dsk;
38
 
//    dsk = getenv("XDG_CURRENT_DESKTOP");
39
 
 
40
 
 
41
 
    this->desktop = qgetenv("XDG_CURRENT_DESKTOP");
42
 
    if(this->desktop.isEmpty())
43
 
        this->desktop = qgetenv("XDG_SESSION_DESKTOP");
44
 
//        qDebug() << this->desktop;
45
 
//    qDebug() << QString::compare(this->desktop, "mate", Qt::CaseInsensitive/*Qt::CaseInsensitive*/);
46
 
 
47
 
//    this->osName = "Kylin";
48
 
//    if (this->arch == "aarch64" || this->osName == "Kylin" || this->osName == "YHKylin") {
49
 
    if (this->desktop == "MATE" || this->desktop == "mate" || this->desktop == "UKUI" || this->desktop == "ukui") {
50
 
        this->isTopLevel();
51
 
        this->resize(900, 600);
52
 
        this->setAutoFillBackground(true);
53
 
        this->setWindowFlags(Qt::FramelessWindowHint | Qt::Widget);
54
 
        this->setWindowTitle(tr("Kylin Assistant"));
55
 
    }
56
 
    else {
57
 
        this->setFixedSize(900, 600);
58
 
        this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowSystemMenuHint);
59
 
        this->setWindowTitle(tr("Youker Assistant"));
60
 
    }
61
 
 
62
 
//    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowSystemMenuHint);
63
 
////    this->setAttribute(Qt::WA_TranslucentBackground, true);
64
 
 
65
 
    this->setWindowIcon(QIcon(":/res/youker-assistant.png"));
66
 
    this->setWindowOpacity(1);
67
 
//    this->setWindowFlags(Qt::FramelessWindowHint | Qt::Widget);
68
 
//    this->setAttribute(Qt::WA_TranslucentBackground);
69
 
//    this->setStyleSheet("QMainWindow{border: 1px solid gray;border-radius:2px}");
70
 
    this->setStyleSheet("QDialog{border: 1px solid white;border-radius:1px;background-color: #ffffff;}");
71
 
//    version = "V2.2.0";
72
 
    status = HOMEPAGE;
73
 
    statusFlag = false;
74
 
 
75
 
    sessioninterface = NULL;
76
 
    systeminterface = NULL;
77
 
 
78
 
    mSettings = new QSettings(YOUKER_COMPANY_SETTING, YOUKER_SETTING_FILE_NAME_SETTING);
79
 
    mSettings->setIniCodec("UTF-8");
80
 
 
81
 
 
82
 
    //judge has skin or not in /var/lib/youker-assistant-daemon/default/
83
 
    mSettings->beginGroup("Background");
84
 
    last_skin_path = mSettings->value("Path").toString();
85
 
    if(last_skin_path.isEmpty()) {
86
 
        last_skin_path = ":/background/res/skin/1.png";
87
 
        mSettings->setValue("Path", last_skin_path);
88
 
    }
89
 
    else {
90
 
        QStringList skinlist = this->filterSkin();
91
 
        QList<QString>::Iterator it = skinlist.begin(), itend = skinlist.end();
92
 
        bool flag = false;
93
 
        for(;it != itend; it++)
94
 
        {
95
 
            if(*it == last_skin_path) {
96
 
                flag = true;
97
 
                break;
98
 
            }
99
 
        }
100
 
        if (flag == false) {
101
 
            last_skin_path = skinlist.at(0);
102
 
            mSettings->setValue("Path", last_skin_path);
103
 
        }
104
 
    }
105
 
 
106
 
    mSettings->endGroup();
107
 
    mSettings->sync();
108
 
    main_skin_pixmap.load(last_skin_path);
109
 
 
110
 
    skin_center = NULL;
111
 
 
112
 
    home_page = NULL;
113
 
    info_widget = NULL;
114
 
    cleaner_widget = NULL;
115
 
    setting_widget = NULL;
116
 
    box_widget = NULL;
117
 
    aboutDlg = NULL;
118
 
 
119
 
    auto_start = NULL;
120
 
    upgrade_dialog = NULL;
121
 
//    camera_manager = NULL;
122
 
 
123
 
    spreadGroup = NULL;
124
 
    gatherGroup = NULL;
125
 
 
126
 
    home_action_widget = NULL;
127
 
    info_action_widget = NULL;
128
 
    cleaner_action_widget = NULL;
129
 
    setting_action_widget = NULL;
130
 
    box_action_widget = NULL;
131
 
 
132
 
    toolKits = new Toolkits(0, this->width(), this->height());
133
 
 
134
 
 
135
 
    shadow_widget = new ShadowWidget(this);
136
 
    shadow_widget->setGeometry(rect());
137
 
//    shadow_widget->setColor(QColor(Qt::gray));
138
 
    shadow_widget->setColor(QColor("#e9eef0"));
139
 
 
140
 
    default_action_widget = new ActionWidget(this);
141
 
    default_action_widget->setGeometry(QRect(0, 0, 900, 227));
142
 
    default_action_widget->setFixedHeight(227);
143
 
    other_action_widget = new ActionWidget(this);
144
 
    other_action_widget->setGeometry(QRect(0, -150, 900, 150));
145
 
    other_action_widget->setFixedHeight(150);
146
 
    topStack = new QStackedWidget(other_action_widget);
147
 
    topStack->setGeometry(other_action_widget->rect());
148
 
 
149
 
    //设置在最底层,方便title_widget的显示
150
 
//    default_action_widget->lower();
151
 
    QPalette palette_back;
152
 
    palette_back.setBrush(QPalette::Background, QBrush(QPixmap(last_skin_path)));
153
 
    default_action_widget->setPalette(palette_back);
154
 
    other_action_widget->setPalette(palette_back);
155
 
 
156
 
    tool_widget = new ToolWidget(this, this->arch, this->osName);
157
 
    tool_widget->setGeometry(QRect(0, 227, 900, 47));
158
 
    tool_widget->setParentWindow(this);
159
 
    connect(this, SIGNAL(chanegBoxToolStatus()), tool_widget, SLOT(showBoxTool()));
160
 
    tool_widget->initConnect();
161
 
 
162
 
    title_widget = new TitleWidget(this, this->arch, this->osName);
163
 
    if (this->arch == "aarch64" || this->osName == "Kylin" || this->osName == "YHKylin")
164
 
        title_widget->move(756, 0);
165
 
    else {
166
 
        title_widget->move(0, 0);
167
 
    }
168
 
    connect(title_widget, SIGNAL(closeApp()), this, SLOT(closeYoukerAssistant()));
169
 
    title_widget->setParentWindow(this);
170
 
    title_widget->initConnect();
171
 
 
172
 
//
173
 
    login_widget = new LoginWidget(this);
174
 
    if (this->arch == "aarch64" || this->osName == "Kylin" || this->osName == "YHKylin")
175
 
        login_widget->hide();
176
 
    else {
177
 
        login_widget->move(585, 0);//900 - login_widget(220) - right_align(15) = 665
178
 
    }
179
 
 
180
 
    default_content_widget = new ContentWidget(this);
181
 
    default_content_widget->setGeometry(QRect(0, 274, 900, 326));
182
 
    default_content_widget->setFixedHeight(326);
183
 
    other_content_widget = new ContentWidget(this);
184
 
    other_content_widget->setGeometry(QRect(0, 600, 900, 403));
185
 
    other_content_widget->setFixedHeight(403);
186
 
    bottomStack = new QStackedWidget(other_content_widget);
187
 
    bottomStack->setGeometry(other_content_widget->rect());
188
 
//    top_grid_layout = NULL;
189
 
//    bottom_grid_layout = NULL;
190
 
 
191
 
    main_menu = new KylinMenu(this);
192
 
    main_menu->setParentWindow(this);
193
 
    main_menu->initConnect();
194
 
 
195
 
    this->initHomePage();
196
 
    this->initAnimation();
197
 
 
198
 
    this->hide();
199
 
    this->startDbusDaemon();
200
 
}
201
 
 
202
 
MainWindow::~MainWindow()
203
 
{
204
 
    if (home_page != NULL)
205
 
    {
206
 
        delete home_page;
207
 
        home_page = NULL;
208
 
    }
209
 
    if (info_widget != NULL)
210
 
    {
211
 
        delete info_widget;
212
 
        info_widget = NULL;
213
 
    }
214
 
    if (cleaner_widget != NULL)
215
 
    {
216
 
        delete cleaner_widget;
217
 
        cleaner_widget = NULL;
218
 
    }
219
 
    if (setting_widget != NULL)
220
 
    {
221
 
        delete setting_widget;
222
 
        setting_widget = NULL;
223
 
    }
224
 
    if (box_widget != NULL)
225
 
    {
226
 
        delete box_widget;
227
 
        box_widget = NULL;
228
 
    }
229
 
    if (setting_action_widget != NULL)
230
 
    {
231
 
        delete setting_action_widget;
232
 
        setting_action_widget = NULL;
233
 
    }
234
 
//    if (sessioninterface != NULL)
235
 
//    {
236
 
//        delete sessioninterface;
237
 
//        sessioninterface = NULL;
238
 
//    }
239
 
//    if (systeminterface != NULL)
240
 
//    {
241
 
//        delete systeminterface;
242
 
//        systeminterface = NULL;
243
 
//    }
244
 
    if (sessioninterface) {
245
 
        sessioninterface->deleteLater();
246
 
    }
247
 
    if (systeminterface) {
248
 
        systeminterface->deleteLater();
249
 
    }
250
 
    ThreadPool::Instance()->deleteLater();
251
 
    if (aboutDlg != NULL)
252
 
    {
253
 
        delete aboutDlg;
254
 
        aboutDlg = NULL;
255
 
    }
256
 
    if (toolKits != NULL)
257
 
    {
258
 
        delete toolKits;
259
 
        toolKits = NULL;
260
 
    }
261
 
    if (mSettings != NULL)
262
 
    {
263
 
        mSettings->sync();
264
 
        delete mSettings;
265
 
        mSettings = NULL;
266
 
    }
267
 
 
268
 
    if(auto_start != NULL)
269
 
    {
270
 
        delete auto_start;
271
 
        auto_start = NULL;
272
 
    }
273
 
//    if(camera_manager != NULL)
274
 
//    {
275
 
//        delete camera_manager;
276
 
//        camera_manager = NULL;
277
 
//    }
278
 
    if(skin_center != NULL)
279
 
    {
280
 
        delete skin_center;
281
 
        skin_center = NULL;
282
 
    }
283
 
    if(upgrade_dialog != NULL)
284
 
    {
285
 
        delete upgrade_dialog;
286
 
        upgrade_dialog = NULL;
287
 
    }
288
 
}
289
 
 
290
 
QString MainWindow::accessOSName()
291
 
{
292
 
 
293
 
    QString osname = "";
294
 
    QString tmp = "";
295
 
 
296
 
    QFile osfile("/etc/os-release");
297
 
    if(osfile.exists()) {
298
 
        if(!osfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
299
 
            qDebug() << "Can't open os-release!" << endl;
300
 
        }
301
 
        else {
302
 
            while(!osfile.atEnd()) {
303
 
                QByteArray line = osfile.readLine();
304
 
                QString str(line);
305
 
                if (str.startsWith("NAME")) {
306
 
                    tmp = str;
307
 
                    break;
308
 
                }
309
 
            }
310
 
            osfile.close();
311
 
        }
312
 
    }
313
 
    if(tmp.length() > 0 && tmp.contains("=")) {
314
 
        osname = QString(tmp.split("=").at(1)).replace("\"", "").replace("\n","").trimmed();
315
 
    }
316
 
    if(osname.length() > 0) {
317
 
        return osname;
318
 
    }
319
 
 
320
 
    osname = "";
321
 
    tmp = "";
322
 
    QFile ukfile("/etc/ubuntukylin-release");
323
 
    if(ukfile.exists()) {
324
 
        if(!ukfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
325
 
            qDebug() << "Can't open ubuntukylin-release!" << endl;
326
 
        }
327
 
        else {
328
 
            while(!ukfile.atEnd()) {
329
 
                QByteArray line = ukfile.readLine();
330
 
                QString str(line);
331
 
                if (str.startsWith("DISTRIB_DESCRIPTION")) {
332
 
                    tmp = str;
333
 
                    break;
334
 
                }
335
 
            }
336
 
            ukfile.close();
337
 
        }
338
 
    }
339
 
    if(tmp.length() > 0 && tmp.contains("=")) {
340
 
        osname = QString(tmp.split("=").at(1)).replace("\"", "").replace("\n","").trimmed();
341
 
    }
342
 
    if(osname.length() > 0) {
343
 
        return osname;
344
 
    }
345
 
 
346
 
    osname = "";
347
 
    tmp = "";
348
 
    QFile lsbfile("/etc/lsb-release");
349
 
    if(lsbfile.exists()) {
350
 
        if(!lsbfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
351
 
            qDebug() << "Can't open lsb-release!" << endl;
352
 
        }
353
 
        else {
354
 
            while(!lsbfile.atEnd()) {
355
 
                QByteArray line = lsbfile.readLine();
356
 
                QString str(line);
357
 
                if (str.startsWith("DISTRIB_DESCRIPTION")) {
358
 
                    tmp = str;
359
 
                    break;
360
 
                }
361
 
            }
362
 
            lsbfile.close();
363
 
        }
364
 
    }
365
 
    if(tmp.length() > 0 && tmp.contains("=")) {
366
 
        osname = QString(tmp.split("=").at(1)).replace("\"", "").replace("\n","").trimmed();
367
 
    }
368
 
    if(osname.length() > 0) {
369
 
        return osname;
370
 
    }
371
 
 
372
 
    return "Ubuntu Kylin";
373
 
}
374
 
 
375
 
bool MainWindow::deleteFile(QString filename)
376
 
{
377
 
    bool result = systeminterface->delete_file_qt(filename);
378
 
    return result;
379
 
}
380
 
 
381
 
bool MainWindow::CopyFile(QString filename)
382
 
{
383
 
    bool result = systeminterface->copy_file_qt(filename);
384
 
    return result;
385
 
}
386
 
 
387
 
QStringList MainWindow::filterSkin()
388
 
{
389
 
    QStringList skinlist;
390
 
    QString path = "/var/lib/youker-assistant-daemon/default/";
391
 
    QString path2 = "/var/lib/youker-assistant-daemon/custom/";
392
 
    QDir picdir(path);
393
 
    picdir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
394
 
    picdir.setSorting(QDir::Size | QDir::Reversed);
395
 
    QDir picdir2(path2);
396
 
    picdir2.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
397
 
    picdir2.setSorting(QDir::Size | QDir::Reversed);
398
 
    QStringList filters;
399
 
    filters << "*.jpg" << "*.png";
400
 
    picdir.setNameFilters(filters);
401
 
    picdir2.setNameFilters(filters);
402
 
    QFileInfoList list = picdir.entryInfoList();
403
 
    QFileInfoList list2 = picdir2.entryInfoList();
404
 
    if(list.size() < 1 && list2.size() < 1) {
405
 
        skinlist << ":/background/res/skin/1.png" << ":/background/res/skin/2.png" << ":/background/res/skin/3.png" << ":/background/res/skin/4.png";
406
 
//        return ":/background/res/skin/1.png";
407
 
    }
408
 
    else if(list.size() > 0 && list2.size() > 0) {
409
 
        for (int j = 0; j < list.size(); ++j) {
410
 
            QFileInfo fileInfo = list.at(j);
411
 
            skinlist << path + fileInfo.fileName();
412
 
        }
413
 
        for (int k = 0; k < list2.size(); ++k) {
414
 
            QFileInfo fileInfo = list2.at(k);
415
 
            skinlist << path2 + fileInfo.fileName();
416
 
        }
417
 
        skinlist << ":/background/res/skin/1.png" << ":/background/res/skin/2.png" << ":/background/res/skin/3.png" << ":/background/res/skin/4.png";
418
 
    }
419
 
    else {
420
 
        if(list.size() > 0) {
421
 
            for (int j = 0; j < list.size(); ++j) {
422
 
                QFileInfo fileInfo = list.at(j);
423
 
                skinlist << path + fileInfo.fileName();
424
 
            }
425
 
            skinlist << ":/background/res/skin/1.png" << ":/background/res/skin/2.png" << ":/background/res/skin/3.png" << ":/background/res/skin/4.png";
426
 
        }
427
 
        else if(list2.size() > 0) {
428
 
            for (int m = 0; m < list2.size(); ++m) {
429
 
                QFileInfo fileInfo = list2.at(m);
430
 
                skinlist << path2 + fileInfo.fileName();
431
 
            }
432
 
            skinlist << ":/background/res/skin/1.png" << ":/background/res/skin/2.png" << ":/background/res/skin/3.png" << ":/background/res/skin/4.png";
433
 
        }
434
 
//        QFileInfo fileInfo = list.at(0);
435
 
//        return path + fileInfo.fileName();
436
 
    }
437
 
    return skinlist;
438
 
}
439
 
 
440
 
void MainWindow::initAnimation()
441
 
{
442
 
    QPoint origPoint(0, 227);
443
 
    QPoint needPoint(0, 150);
444
 
    QPoint origPoint1(0, 0);
445
 
    QPoint needPoint1(0, -227);
446
 
    QPoint origPoint2(0, -150);
447
 
    QPoint needPoint2(0, 0);
448
 
 
449
 
    QPoint origPoint3(0, 274);
450
 
    QPoint needPoint3(0, 600);
451
 
    QPoint origPoint4(0, 600);
452
 
    QPoint needPoint4(0, 197);
453
 
 
454
 
    QPropertyAnimation *mainActionAnimation = new QPropertyAnimation(default_action_widget, "pos");
455
 
    mainActionAnimation->setDuration(500);
456
 
    mainActionAnimation->setStartValue(origPoint1);
457
 
    mainActionAnimation->setEndValue(needPoint1);
458
 
 
459
 
    QPropertyAnimation *mainActionAnimation2 = new QPropertyAnimation(other_action_widget, "pos");
460
 
    mainActionAnimation2->setDuration(500);
461
 
    mainActionAnimation2->setStartValue(origPoint2);
462
 
    mainActionAnimation2->setEndValue(needPoint2);
463
 
 
464
 
    QPropertyAnimation *mainToolAnimation = new QPropertyAnimation(tool_widget, "pos");
465
 
    mainToolAnimation->setDuration(500);
466
 
    mainToolAnimation->setStartValue(origPoint);
467
 
    mainToolAnimation->setEndValue(needPoint);
468
 
 
469
 
    QPropertyAnimation *mainContentAnimation = new QPropertyAnimation(default_content_widget, "pos");
470
 
    mainContentAnimation->setDuration(500);
471
 
    mainContentAnimation->setStartValue(origPoint3);
472
 
    mainContentAnimation->setEndValue(needPoint3);
473
 
 
474
 
    QPropertyAnimation *mainContentAnimation2 = new QPropertyAnimation(other_content_widget, "pos");
475
 
    mainContentAnimation2->setDuration(500);
476
 
    mainContentAnimation2->setStartValue(origPoint4);
477
 
    mainContentAnimation2->setEndValue(needPoint4);
478
 
 
479
 
    QPropertyAnimation  *m_toTrans = new QPropertyAnimation(shadow_widget, "opacity");
480
 
    m_toTrans->setDuration(200);
481
 
    m_toTrans->setStartValue(1);
482
 
    m_toTrans->setEndValue(0);
483
 
 
484
 
    spreadGroup = new QParallelAnimationGroup(this);
485
 
    spreadGroup->addAnimation(mainActionAnimation);
486
 
    spreadGroup->addAnimation(mainActionAnimation2);
487
 
    spreadGroup->addAnimation(mainToolAnimation);
488
 
    spreadGroup->addAnimation(mainContentAnimation);
489
 
    spreadGroup->addAnimation(mainContentAnimation2);
490
 
    spreadGroup->addAnimation(m_toTrans);
491
 
 
492
 
    QPropertyAnimation *mainActionBackAnimation2 = new QPropertyAnimation(other_action_widget, "pos");
493
 
    mainActionBackAnimation2->setDuration(500);
494
 
    mainActionBackAnimation2->setStartValue(needPoint2);
495
 
    mainActionBackAnimation2->setEndValue(origPoint2);
496
 
 
497
 
    QPropertyAnimation *mainActionBackAnimation = new QPropertyAnimation(default_action_widget, "pos");
498
 
    mainActionBackAnimation->setDuration(500);
499
 
    mainActionBackAnimation->setStartValue(needPoint1);
500
 
    mainActionBackAnimation->setEndValue(origPoint1);
501
 
 
502
 
    QPropertyAnimation *mainToolBackAnimation = new QPropertyAnimation(tool_widget, "pos");
503
 
    mainToolBackAnimation->setDuration(500);
504
 
    mainToolBackAnimation->setStartValue(needPoint);
505
 
    mainToolBackAnimation->setEndValue(origPoint);
506
 
 
507
 
 
508
 
    QPropertyAnimation *mainContentBackAnimation = new QPropertyAnimation(default_content_widget, "pos");
509
 
    mainContentBackAnimation->setDuration(500);
510
 
    mainContentBackAnimation->setStartValue(needPoint3);
511
 
    mainContentBackAnimation->setEndValue(origPoint3);
512
 
 
513
 
    QPropertyAnimation *mainContentBackAnimation2 = new QPropertyAnimation(other_content_widget, "pos");
514
 
    mainContentBackAnimation2->setDuration(500);
515
 
    mainContentBackAnimation2->setStartValue(needPoint4);
516
 
    mainContentBackAnimation2->setEndValue(origPoint4);
517
 
 
518
 
    QPropertyAnimation  *m_toGray = new QPropertyAnimation(shadow_widget, "opacity");
519
 
    m_toGray->setDuration(200);
520
 
    m_toGray->setStartValue(0);
521
 
    m_toGray->setEndValue(1);
522
 
 
523
 
    gatherGroup = new QParallelAnimationGroup(this);
524
 
    gatherGroup->addAnimation(mainActionBackAnimation);
525
 
    gatherGroup->addAnimation(mainActionBackAnimation2);
526
 
    gatherGroup->addAnimation(mainToolBackAnimation);
527
 
    gatherGroup->addAnimation(mainContentBackAnimation);
528
 
    gatherGroup->addAnimation(mainContentBackAnimation2);
529
 
    gatherGroup->addAnimation(m_toGray);
530
 
 
531
 
    connect(spreadGroup, SIGNAL(finished()), this, SLOT(upAnimFinished()));
532
 
    connect(gatherGroup, SIGNAL(finished()), this, SLOT(closeAnimFinished()));
533
 
}
534
 
 
535
 
void MainWindow::upAnimFinished()
536
 
{
537
 
    tool_widget->show();
538
 
    shadow_widget->hide();
539
 
    if(title_widget->isHidden())
540
 
        title_widget->show();
541
 
    if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin")
542
 
    {
543
 
        if(status == BOXPAGE && login_widget->isHidden()) {
544
 
            login_widget->show();
545
 
        }
546
 
        else {
547
 
            login_widget->hide();
548
 
        }
549
 
    }
550
 
}
551
 
 
552
 
void MainWindow::closeAnimFinished()
553
 
{
554
 
    tool_widget->show();
555
 
    if(title_widget->isHidden())
556
 
        title_widget->show();
557
 
    if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin" && login_widget->isHidden())
558
 
    {
559
 
        login_widget->show();
560
 
    }
561
 
    shadow_widget->hide();
562
 
}
563
 
 
564
 
void MainWindow::setTranslator(QTranslator* translator)
565
 
{
566
 
    this->translator = translator;
567
 
}
568
 
 
569
 
void MainWindow::changeLanguage(LANGUAGE language)
570
 
{
571
 
    if(current_language == language)
572
 
    {
573
 
        return;
574
 
    }
575
 
    current_language = language;
576
 
 
577
 
    switch(language)
578
 
    {
579
 
    case YOUKER_EN:
580
 
        translator->load(QString(":/qmfile/res/qm/youker-assistant_es.qm"));
581
 
        break;
582
 
 
583
 
    case YOUKER_ZH_CN:
584
 
        translator->load(QString(":/qmfile/res/qm/youker-assistant_zh_CN.qm"));
585
 
        break;
586
 
 
587
 
    case YOUKER_ES:
588
 
        translator->load(QString(":/qmfile/res/qm/youker-assistant_es.qm"));
589
 
        break;
590
 
 
591
 
    default:
592
 
        translator->load(QString(":/qmfile/res/qm/youker-assistant_zh_CN.qm"));
593
 
    }
594
 
 
595
 
//      title_widget->translateLanguage();
596
 
//      kill_mummy_widget->translateLanguage();
597
 
//      main_menu->translateActions();
598
 
//      character_widget->translateLanguage();
599
 
//      login_dialog->translateLanguage();
600
 
//      register_widget->translateLanguage();
601
 
//      character_widget->translateLanguage();
602
 
//      about_us_dialog->translateLanguage();
603
 
//      setting_dialog->translateLanguage();
604
 
//      skin_widget->translateLanguage();
605
 
//      system_tray->translateLanguage();
606
 
}
607
 
 
608
 
void MainWindow::displayMainWindow(/*int count*/)
609
 
{
610
 
    this->battery = sessioninterface->judge_power_is_exists_qt();
611
 
    this->sensor = systeminterface->judge_sensors_exists_qt();
612
 
    login_widget->setSessionDbusProxy(sessioninterface);
613
 
    if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin")
614
 
        sessioninterface->check_user_qt();
615
 
    connect(sessioninterface, SIGNAL(ssoSuccessSignal(QString, QString)), login_widget, SLOT(showLoginInfo(QString,QString)));
616
 
    connect(sessioninterface, SIGNAL(ssoLoginLogoutSignal(bool)), login_widget, SLOT(showLoginAndLogoutStatus(bool)));
617
 
    home_action_widget->setSessionDbusProxy(sessioninterface);
618
 
    home_action_widget->setSystemDbusProxy(systeminterface);
619
 
    home_action_widget->enableSanButton();
620
 
    connect(sessioninterface, SIGNAL(isScanning(QString)), home_action_widget, SLOT(getScanResult(QString)));
621
 
    connect(sessioninterface, SIGNAL(finishScanWork(QString)), home_action_widget, SLOT(finishScanResult(QString)));
622
 
    connect(sessioninterface, SIGNAL(tellScanResult(QString,QString)) ,home_action_widget, SLOT(getScanAllResult(QString,QString)));
623
 
    connect(systeminterface, SIGNAL(finishCleanWorkMain(QString/*, QString*/)), home_action_widget, SLOT(getCleanResult(QString/*, QString*/)));
624
 
    connect(systeminterface, SIGNAL(finishCleanWorkMainError(QString)), home_action_widget, SLOT(finishCleanError(QString)));
625
 
    connect(systeminterface, SIGNAL(quickCleanProcess(QString,QString)), home_action_widget, SLOT(getCleaningMessage(QString,QString)));
626
 
    home_page->setSessionDbusProxy(sessioninterface);
627
 
    home_page->setSystemDbusProxy(systeminterface);
628
 
    this->initOtherPages();
629
 
 
630
 
//    if (this->isHidden()) {
631
 
    int windowWidth, windowHeight = 0;
632
 
    if (this->display_count < 2) {
633
 
        windowWidth = QApplication::desktop()->width();
634
 
        windowHeight = QApplication::desktop()->height();
635
 
        this->move((windowWidth - this->width()) / 2,(windowHeight - this->height()) / 2);
636
 
    }
637
 
    else {
638
 
        /*this->setGeometry(QApplication::desktop()->screenGeometry(1));
639
 
        int a_width = 0;
640
 
        for (int i=0;i<count;i++) {
641
 
            if (i != 1)
642
 
                a_width += QApplication::desktop()->screenGeometry(i).width();//QRect QApplication::desktop->screenGeometry(1);根据当前的屏幕序号获取屏幕宽高等属性
643
 
        }
644
 
        windowWidth = QApplication::desktop()->width() - a_width;//QApplication::desktop()->width();获取虚拟屏幕全宽,注意这个比较猛,是获取的总宽度,对于横向扩展屏来说,也就是 屏幕1+ 屏幕2 + ... 的宽度
645
 
        windowHeight = QApplication::desktop()->screenGeometry(1).height();
646
 
        qDebug() << windowWidth;//3286   1024   1920  1366
647
 
        qDebug() << windowHeight;//1080   768    1080  768
648
 
        qDebug() << this->width();//900
649
 
        qDebug() << this->height();//600
650
 
        this->move((windowWidth - this->width()) / 2,(windowHeight - this->height()) / 2);*/
651
 
        windowWidth = QApplication::desktop()->screenGeometry(0).width();
652
 
        windowHeight = QApplication::desktop()->screenGeometry(0).height();
653
 
        this->move((windowWidth - this->width()) / 2,(windowHeight - this->height()) / 2);
654
 
    }
655
 
 
656
 
    this->show();
657
 
    this->raise();
658
 
//    QTimer::singleShot(100, this, SLOT(startDbusDaemon()));
659
 
//    }
660
 
//    else {
661
 
//        this->hide();
662
 
//    }
663
 
}
664
 
 
665
 
inline bool isRunningInstalled() {
666
 
    static bool installed = (QCoreApplication::applicationDirPath() ==
667
 
                             QDir(("/usr/bin")).canonicalPath());
668
 
    return installed;
669
 
}
670
 
 
671
 
inline QString getAppDirectory() {
672
 
    if (isRunningInstalled()) {
673
 
        return QString("/var/lib/youker-assistant-daemon/");
674
 
    } else {
675
 
        return QString(QCoreApplication::applicationDirPath());
676
 
    }
677
 
}
678
 
 
679
 
void MainWindow::startDbusDaemon()
680
 
{
681
 
    sessioninterface = new SessionDispatcher;
682
 
    systeminterface = new SystemDispatcher;
683
 
    QThread *sessionThread = ThreadPool::Instance()->createNewThread();
684
 
    sessioninterface->moveToThread(sessionThread);
685
 
    sessionThread->start();
686
 
    QThread *systemThread = ThreadPool::Instance()->createNewThread();
687
 
    systeminterface->moveToThread(systemThread);
688
 
    connect(systemThread, SIGNAL(started()), systeminterface, SLOT(initData()));
689
 
 
690
 
//    connect(systeminterface, &SystemDispatcher::dbusInitFinished, this, [=] {dlg.close();this->displayMainWindow();
691
 
//    });
692
 
    connect(systeminterface, SIGNAL(dbusInitFinished()), this, SLOT(displayMainWindow()));//数据获取完毕后,告诉界面去更新数据后显示界面
693
 
    systemThread->start();
694
 
 
695
 
 
696
 
    /*sessioninterface = new SessionDispatcher(this);
697
 
    systeminterface = new SystemDispatcher(this);
698
 
//    this->desktop = sessioninterface->access_current_desktop_qt();
699
 
//    this->osName = systeminterface->get_os_name_qt();
700
 
//    this->machine = sessioninterface->access_current_machine_qt();//x86_64
701
 
    this->battery = sessioninterface->judge_power_is_exists_qt();
702
 
    this->sensor = systeminterface->judge_sensors_exists_qt();
703
 
    login_widget->setSessionDbusProxy(sessioninterface);
704
 
    if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin")
705
 
        sessioninterface->check_user_qt();
706
 
    connect(sessioninterface, SIGNAL(ssoSuccessSignal(QString, QString)), login_widget, SLOT(showLoginInfo(QString,QString)));
707
 
    connect(sessioninterface, SIGNAL(ssoLoginLogoutSignal(bool)), login_widget, SLOT(showLoginAndLogoutStatus(bool)));
708
 
    home_action_widget->setSessionDbusProxy(sessioninterface);
709
 
    home_action_widget->setSystemDbusProxy(systeminterface);
710
 
    home_action_widget->enableSanButton();
711
 
    connect(sessioninterface, SIGNAL(isScanning(QString)), home_action_widget, SLOT(getScanResult(QString)));
712
 
    connect(sessioninterface, SIGNAL(finishScanWork(QString)), home_action_widget, SLOT(finishScanResult(QString)));
713
 
    connect(sessioninterface, SIGNAL(tellScanResult(QString,QString)) ,home_action_widget, SLOT(getScanAllResult(QString,QString)));
714
 
    connect(systeminterface, SIGNAL(finishCleanWorkMain(QString)), home_action_widget, SLOT(getCleanResult(QString)));
715
 
    connect(systeminterface, SIGNAL(finishCleanWorkMainError(QString)), home_action_widget, SLOT(finishCleanError(QString)));
716
 
    connect(systeminterface, SIGNAL(quickCleanProcess(QString,QString)), home_action_widget, SLOT(getCleaningMessage(QString,QString)));
717
 
    home_page->setSessionDbusProxy(sessioninterface);
718
 
    home_page->setSystemDbusProxy(systeminterface);
719
 
    this->initOtherPages();*/
720
 
}
721
 
 
722
 
void MainWindow::initOtherPages()
723
 
{
724
 
    if(cleaner_action_widget == NULL)
725
 
        cleaner_action_widget = new CleanerActionWidget(this);
726
 
    topStack->addWidget(cleaner_action_widget);
727
 
    if(info_action_widget == NULL)
728
 
        info_action_widget = new InfoActionWidget(this);
729
 
    topStack->addWidget(info_action_widget);
730
 
    if(setting_action_widget == NULL)
731
 
        setting_action_widget = new SettingActionWidget();
732
 
    topStack->addWidget(setting_action_widget);
733
 
    if(box_action_widget == NULL)
734
 
        box_action_widget = new BoxActionWidget(this);
735
 
    topStack->addWidget(box_action_widget);
736
 
 
737
 
    if(cleaner_widget == NULL)
738
 
        cleaner_widget = new CleanerWidget();
739
 
    cleaner_widget->setSessionDbusProxy(sessioninterface);
740
 
    cleaner_widget->setSystemDbusProxy(systeminterface);
741
 
    cleaner_widget->setToolKits(toolKits);
742
 
    cleaner_widget->setParentWindow(this);
743
 
    cleaner_widget->initUI(last_skin_path);
744
 
    connect(cleaner_action_widget, SIGNAL(showDetailData()),cleaner_widget, SLOT(displayDetailPage()));
745
 
    connect(cleaner_action_widget, SIGNAL(showMainData()),cleaner_widget, SLOT(displayMainPage()));
746
 
    connect(cleaner_action_widget, SIGNAL(sendCleanSignal()),cleaner_widget, SIGNAL(transCleanSignal()));
747
 
    connect(systeminterface, SIGNAL(sendCleanOverSignal()), cleaner_widget, SLOT(displayMainPage()));
748
 
    connect(systeminterface, SIGNAL(sendCleanOverSignal()), cleaner_action_widget, SLOT(displayOrgPage()));
749
 
    //kobe
750
 
    connect(systeminterface, SIGNAL(policykitCleanSignal(bool)), cleaner_action_widget, SLOT(receivePolicyKitSignal(bool)));
751
 
    connect(systeminterface, SIGNAL(sendCleanOverSignal()), cleaner_action_widget, SLOT(showCleanOverStatus()));
752
 
    connect(systeminterface, SIGNAL(tellCleanerMainData(QStringList)), cleaner_action_widget, SLOT(showCleanerData(QStringList)));
753
 
    connect(systeminterface, SIGNAL(tellCleanerMainStatus(QString, QString)), cleaner_action_widget, SLOT(showCleanerStatus(QString, QString)));
754
 
    connect(systeminterface, SIGNAL(sendCleanErrorSignal(QString)), cleaner_action_widget, SLOT(showCleanerError(QString)));
755
 
    connect(sessioninterface, SIGNAL(tellCleanerDetailStatus(QString)), cleaner_action_widget, SLOT(showCleanReciveStatus(QString)));
756
 
    connect(sessioninterface, SIGNAL(tellCleanerDetailError(QString)), cleaner_action_widget, SLOT(showCleanReciveError(QString)));
757
 
 
758
 
 
759
 
    connect(cleaner_action_widget, SIGNAL(sendScanSignal()),cleaner_widget, SIGNAL(transScanSignal()));
760
 
    connect(cleaner_widget, SIGNAL(tranActionAnimaitonSignal()),cleaner_action_widget, SLOT(displayAnimation()));
761
 
    connect(cleaner_widget, SIGNAL(tranScanOverSignal(bool)),cleaner_action_widget, SLOT(accordScanOverStatusToChange(bool)));
762
 
    bottomStack->addWidget(cleaner_widget);
763
 
 
764
 
    if(info_widget == NULL)
765
 
        info_widget = new InfoWidget(this->arch);
766
 
    info_widget->setSessionDbusProxy(sessioninterface);
767
 
    info_widget->setSystemDbusProxy(systeminterface);
768
 
    info_widget->initUI(this->battery, this->sensor);
769
 
    bottomStack->addWidget(info_widget);
770
 
 
771
 
    if(setting_widget == NULL)
772
 
        setting_widget = new SettingWidget(this->desktop, this->battery);
773
 
    setting_widget->setParentWindow(this);
774
 
    setting_widget->setSessionDbusProxy(sessioninterface);
775
 
    setting_widget->setSystemDbusProxy(systeminterface);
776
 
    setting_widget->initUI(last_skin_path);
777
 
    connect(setting_widget, SIGNAL(changeActionPage(int)), setting_action_widget, SLOT(displayActionSubPage(int)));
778
 
    connect(setting_action_widget, SIGNAL(notifyContentPageToMain()), setting_widget, SLOT(displaySettingHomePage()));
779
 
    bottomStack->addWidget(setting_widget);
780
 
 
781
 
    if(box_widget == NULL)
782
 
        box_widget = new BoxWidget(this, this->arch, this->osName, getAppDirectory());
783
 
    box_widget->setSessionDbusProxy(sessioninterface);
784
 
    connect(box_widget, SIGNAL(sendSubIndex(int)), this, SLOT(displaySubPage(int)));
785
 
    bottomStack->addWidget(box_widget);
786
 
}
787
 
 
788
 
int MainWindow::getCurrentBackgroundIndex()
789
 
{
790
 
    int index = 1;
791
 
    mSettings->beginGroup("Background");
792
 
    QString cur_skin_path = mSettings->value("Path").toString();
793
 
    if(!cur_skin_path.isEmpty()) {
794
 
        int  start_pos = cur_skin_path.lastIndexOf("/") + 1;
795
 
        int end_pos = cur_skin_path.length();
796
 
        index = cur_skin_path.mid(start_pos, end_pos-start_pos).replace(".png", "").toInt();
797
 
    }
798
 
    mSettings->endGroup();
799
 
    mSettings->sync();
800
 
    return index;
801
 
}
802
 
 
803
 
QString MainWindow::getCurrentBackgroundName()
804
 
{
805
 
    QString cur_skin_path;
806
 
    mSettings->beginGroup("Background");
807
 
    cur_skin_path = mSettings->value("Path").toString();
808
 
    if(!cur_skin_path.isEmpty()) {
809
 
        int  start_pos = cur_skin_path.lastIndexOf("/") + 1;
810
 
        int end_pos = cur_skin_path.length();
811
 
        cur_skin_path = cur_skin_path.mid(start_pos, end_pos-start_pos);
812
 
    }
813
 
    mSettings->endGroup();
814
 
    mSettings->sync();
815
 
    return cur_skin_path;
816
 
}
817
 
 
818
 
QString MainWindow::getCurrentBackgroundAbsName()
819
 
{
820
 
    QString cur_skin_path;
821
 
    mSettings->beginGroup("Background");
822
 
    cur_skin_path = mSettings->value("Path").toString();
823
 
    mSettings->endGroup();
824
 
    mSettings->sync();
825
 
    return cur_skin_path;
826
 
}
827
 
 
828
 
void MainWindow::restoreSkin()
829
 
{
830
 
  if (main_skin_pixmap.isDetached())
831
 
  {
832
 
    main_skin_pixmap.detach();
833
 
  }
834
 
  main_skin_pixmap.load(last_skin_path);
835
 
  QPalette palette_back;
836
 
  palette_back.setBrush(QPalette::Background, main_skin_pixmap);
837
 
  default_action_widget->setPalette(palette_back);
838
 
  other_action_widget->setPalette(palette_back);
839
 
}
840
 
 
841
 
 
842
 
void MainWindow::changeSkin(QString pciture)
843
 
{
844
 
    if (main_skin_pixmap.isDetached())
845
 
    {
846
 
        main_skin_pixmap.detach();
847
 
    }
848
 
    last_skin_path = pciture;
849
 
    main_skin_pixmap.load(pciture);
850
 
    QPalette palette;
851
 
    palette.setBrush(QPalette::Background, main_skin_pixmap);
852
 
    default_action_widget->setPalette(palette);
853
 
    other_action_widget->setPalette(palette);
854
 
 
855
 
    mSettings->beginGroup("Background");
856
 
    mSettings->setValue("Path", pciture);
857
 
    mSettings->endGroup();
858
 
    mSettings->sync();
859
 
 
860
 
    if(auto_start != NULL) {
861
 
        auto_start->resetTitleSkin(last_skin_path);
862
 
    }
863
 
//    if(camera_manager != NULL) {
864
 
//        camera_manager->resetTitleSkin(last_skin_path);
865
 
//    }
866
 
    if(setting_widget != NULL) {
867
 
        setting_widget->resetSkin(last_skin_path);
868
 
    }
869
 
    if(cleaner_widget != NULL) {
870
 
        cleaner_widget->resetSkin(last_skin_path);
871
 
    }
872
 
    if(aboutDlg != NULL) {
873
 
        aboutDlg->resetTitleSkin(last_skin_path);
874
 
    }
875
 
    if(upgrade_dialog != NULL) {
876
 
        upgrade_dialog->resetTitleSkin(last_skin_path);
877
 
    }
878
 
}
879
 
 
880
 
void MainWindow::reViewThePointSkin(QString pciture)
881
 
{
882
 
    if (review_skin_pixmap.isDetached())
883
 
    {
884
 
        review_skin_pixmap.detach();
885
 
    }
886
 
    review_skin_pixmap.load(pciture);
887
 
    QPalette palette_back;
888
 
    palette_back.setBrush(QPalette::Background, review_skin_pixmap);
889
 
    default_action_widget->setPalette(palette_back);
890
 
    other_action_widget->setPalette(palette_back);
891
 
}
892
 
 
893
 
void MainWindow::reViewTheOrgSkin()
894
 
{
895
 
    if (review_skin_pixmap.isDetached())
896
 
    {
897
 
        review_skin_pixmap.detach();
898
 
    }
899
 
    review_skin_pixmap.load(last_skin_path);
900
 
    QPalette palette_back;
901
 
    palette_back.setBrush(QPalette::Background, review_skin_pixmap);
902
 
    default_action_widget->setPalette(palette_back);
903
 
    other_action_widget->setPalette(palette_back);
904
 
}
905
 
 
906
 
void MainWindow::showMainMenu() {
907
 
    if (this->arch == "aarch64" || this->osName == "Kylin" || this->osName == "YHKylin")
908
 
    {
909
 
        QPoint p = rect().topRight();
910
 
        p.setX(p.x() - 180);
911
 
        p.setY(p.y() + 22);
912
 
        main_menu->exec(this->mapToGlobal(p));
913
 
    }
914
 
    else
915
 
    {
916
 
        QPoint p = rect().topLeft();
917
 
        p.setX(p.x() + 107);//104
918
 
        p.setY(p.y() + 22);
919
 
        main_menu->exec(this->mapToGlobal(p));
920
 
    }
921
 
 
922
 
//    //向上弹出menu
923
 
//    QPoint pos;
924
 
//    pos.setX(0);
925
 
//    pos.setY(-main_menu->sizeHint().height());
926
 
//    main_menu->exec(title_widget->mapToGlobal(pos));
927
 
}
928
 
 
929
 
void MainWindow::closeYoukerAssistant() {
930
 
//    qApp->exit();
931
 
    QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
932
 
    animation->setDuration(500);
933
 
    animation->setStartValue(1);
934
 
    animation->setEndValue(0);
935
 
    animation->start();
936
 
    connect(animation, SIGNAL(finished()), this, SLOT(close()));
937
 
}
938
 
 
939
 
void MainWindow::closeEvent(QCloseEvent *)
940
 
{
941
 
//    QApplication::quit();
942
 
    qApp->exit();
943
 
}
944
 
 
945
 
void MainWindow::setCurrentPageIndex(int index)
946
 
{
947
 
    if(index == 0)
948
 
    {
949
 
        if (this->arch == "aarch64" || this->osName == "Kylin" || this->osName == "YHKylin")
950
 
            login_widget->hide();
951
 
        if (status != HOMEPAGE) {
952
 
            statusFlag = true;
953
 
            shadow_widget->show();
954
 
            tool_widget->hide();
955
 
            if(title_widget->isVisible())
956
 
                title_widget->hide();
957
 
            if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin" && login_widget->isVisible())
958
 
            {
959
 
                login_widget->hide();
960
 
            }
961
 
            gatherGroup->start();
962
 
            status = HOMEPAGE;
963
 
        }
964
 
        else
965
 
            statusFlag = false;
966
 
    }
967
 
    else if(index == 1)
968
 
    {
969
 
        if (this->arch == "aarch64" || this->osName == "Kylin" || this->osName == "YHKylin")
970
 
            login_widget->hide();
971
 
        if (status == HOMEPAGE) {
972
 
            statusFlag = true;
973
 
        }
974
 
        else {
975
 
            statusFlag = false;
976
 
        }
977
 
        if (status != CLEANPAGE && statusFlag) {
978
 
            shadow_widget->show();
979
 
            tool_widget->hide();
980
 
            if(title_widget->isVisible())
981
 
                title_widget->hide();
982
 
            if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin" && login_widget->isVisible()) {
983
 
                login_widget->hide();
984
 
            }
985
 
//            topStack->setCurrentIndex(0);
986
 
//            bottomStack->setCurrentIndex(0);
987
 
            topStack->setCurrentWidget(cleaner_action_widget);
988
 
            bottomStack->setCurrentWidget(cleaner_widget);
989
 
            spreadGroup->start();
990
 
            status = CLEANPAGE;
991
 
        }
992
 
        else {
993
 
            if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin" && login_widget->isVisible()) {
994
 
                login_widget->hide();
995
 
            }
996
 
//            topStack->setCurrentIndex(0);
997
 
//            bottomStack->setCurrentIndex(0);
998
 
            topStack->setCurrentWidget(cleaner_action_widget);
999
 
            bottomStack->setCurrentWidget(cleaner_widget);
1000
 
        }
1001
 
    }
1002
 
    else if(index == 2)
1003
 
    {
1004
 
        if (this->arch == "aarch64" || this->osName == "Kylin" || this->osName == "YHKylin" )
1005
 
            login_widget->hide();
1006
 
        if (status == HOMEPAGE) {
1007
 
            statusFlag = true;
1008
 
        }
1009
 
        else {
1010
 
            statusFlag = false;
1011
 
        }
1012
 
        if (status != INFOPAGE && statusFlag) {
1013
 
            shadow_widget->show();
1014
 
            tool_widget->hide();
1015
 
            if(title_widget->isVisible())
1016
 
                title_widget->hide();
1017
 
            if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin" && login_widget->isVisible()) {
1018
 
                login_widget->hide();
1019
 
            }
1020
 
//            topStack->setCurrentIndex(1);
1021
 
//            bottomStack->setCurrentIndex(1);
1022
 
            topStack->setCurrentWidget(info_action_widget);
1023
 
            bottomStack->setCurrentWidget(info_widget);
1024
 
            spreadGroup->start();
1025
 
            status = INFOPAGE;
1026
 
        }
1027
 
        else {
1028
 
            if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin" && login_widget->isVisible()) {
1029
 
                login_widget->hide();
1030
 
            }
1031
 
//            topStack->setCurrentIndex(1);
1032
 
//            bottomStack->setCurrentIndex(1);
1033
 
            topStack->setCurrentWidget(info_action_widget);
1034
 
            bottomStack->setCurrentWidget(info_widget);
1035
 
        }
1036
 
    }
1037
 
    else if(index == 3)
1038
 
    {
1039
 
        if (status == HOMEPAGE)
1040
 
            statusFlag = true;
1041
 
        else
1042
 
            statusFlag = false;
1043
 
        if (this->arch == "aarch64" || this->osName == "Kylin" || this->osName == "YHKylin" )
1044
 
        {
1045
 
            login_widget->hide();
1046
 
            if (status != BOXPAGE && statusFlag) {
1047
 
                shadow_widget->show();
1048
 
                tool_widget->hide();
1049
 
                if(title_widget->isVisible())
1050
 
                    title_widget->hide();
1051
 
    //            topStack->setCurrentIndex(3);
1052
 
    //            bottomStack->setCurrentIndex(3);
1053
 
                topStack->setCurrentWidget(box_action_widget);
1054
 
                bottomStack->setCurrentWidget(box_widget);
1055
 
                spreadGroup->start();
1056
 
                status = BOXPAGE;
1057
 
            }
1058
 
            else {
1059
 
    //            topStack->setCurrentIndex(3);
1060
 
    //            bottomStack->setCurrentIndex(3);
1061
 
                topStack->setCurrentWidget(box_action_widget);
1062
 
                bottomStack->setCurrentWidget(box_widget);
1063
 
            }
1064
 
        }
1065
 
        else
1066
 
        {
1067
 
            if (status != SETTINGPAGE && statusFlag) {
1068
 
                shadow_widget->show();
1069
 
                tool_widget->hide();
1070
 
                if(title_widget->isVisible())
1071
 
                    title_widget->hide();
1072
 
                if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin" && login_widget->isVisible()) {
1073
 
                    login_widget->hide();
1074
 
                }
1075
 
    //            topStack->setCurrentIndex(2);
1076
 
    //            bottomStack->setCurrentIndex(2);
1077
 
                topStack->setCurrentWidget(setting_action_widget);
1078
 
                bottomStack->setCurrentWidget(setting_widget);
1079
 
                spreadGroup->start();
1080
 
                status = SETTINGPAGE;
1081
 
            }
1082
 
            else {
1083
 
                if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin" && login_widget->isVisible()) {
1084
 
                    login_widget->hide();
1085
 
                }
1086
 
    //            topStack->setCurrentIndex(2);
1087
 
    //            bottomStack->setCurrentIndex(2);
1088
 
                topStack->setCurrentWidget(setting_action_widget);
1089
 
                bottomStack->setCurrentWidget(setting_widget);
1090
 
            }
1091
 
        }
1092
 
    }
1093
 
    else if(index == 4)
1094
 
    {
1095
 
        if (this->arch != "aarch64" && this->osName != "Kylin" && this->osName != "YHKylin")
1096
 
        {
1097
 
            if (status == HOMEPAGE)
1098
 
                statusFlag = true;
1099
 
            else
1100
 
                statusFlag = false;
1101
 
            if (status != BOXPAGE && statusFlag) {
1102
 
                shadow_widget->show();
1103
 
                tool_widget->hide();
1104
 
                if(title_widget->isVisible())
1105
 
                    title_widget->hide();
1106
 
                if (login_widget->isVisible()) {
1107
 
                    login_widget->hide();
1108
 
                }
1109
 
    //            topStack->setCurrentIndex(3);
1110
 
    //            bottomStack->setCurrentIndex(3);
1111
 
                topStack->setCurrentWidget(box_action_widget);
1112
 
                bottomStack->setCurrentWidget(box_widget);
1113
 
                spreadGroup->start();
1114
 
                status = BOXPAGE;
1115
 
            }
1116
 
            else {
1117
 
                if (login_widget->isHidden()) {
1118
 
                    login_widget->show();
1119
 
                }
1120
 
    //            topStack->setCurrentIndex(3);
1121
 
    //            bottomStack->setCurrentIndex(3);
1122
 
                topStack->setCurrentWidget(box_action_widget);
1123
 
                bottomStack->setCurrentWidget(box_widget);
1124
 
            }
1125
 
        }
1126
 
    }
1127
 
}
1128
 
 
1129
 
void MainWindow::initHomePage()
1130
 
{
1131
 
    if(home_action_widget == NULL)
1132
 
    {
1133
 
//        if(top_grid_layout == NULL )
1134
 
        QGridLayout *home_top_grid_layout = new QGridLayout();
1135
 
//        home_action_widget = new HomeActionWidget(this, mSettings);
1136
 
        home_action_widget = new HomeActionWidget(0, mSettings);
1137
 
        home_top_grid_layout->addWidget(home_action_widget,0,0);
1138
 
        default_action_widget->setLayout(home_top_grid_layout);
1139
 
        home_top_grid_layout->setSpacing(0);
1140
 
        home_top_grid_layout->setContentsMargins(0, 0, 0, 0);
1141
 
    }
1142
 
 
1143
 
    if(home_page == NULL)
1144
 
    {
1145
 
//        if( bottom_grid_layout == NULL )
1146
 
        QGridLayout *home_bottom_grid_layout = new QGridLayout();
1147
 
//        home_page = new HomePage(0/*, version*/);
1148
 
        home_page = new HomePage(this, this->arch, this->osName/*, version*/);
1149
 
        connect(home_page, SIGNAL(sendSubIndex(int)), this, SLOT(displaySubPage(int)));
1150
 
        home_page->setParentWindow(this);
1151
 
        home_page->initUI();
1152
 
        home_page->initConnect();
1153
 
 
1154
 
        home_bottom_grid_layout->addWidget(home_page,0,0);
1155
 
        default_content_widget->setLayout(home_bottom_grid_layout);
1156
 
        home_bottom_grid_layout->setSpacing(0);
1157
 
        home_bottom_grid_layout->setContentsMargins(0, 0, 0, 0);
1158
 
    }
1159
 
}
1160
 
 
1161
 
void MainWindow::openSkinCenter() {
1162
 
    if(skin_center == NULL) {
1163
 
        skin_center = new SkinCenter(0, last_skin_path, this->arch, this->osName);//20161228
1164
 
        skin_center->setParentWindow(this);
1165
 
        skin_center->initSysBackgroundList();
1166
 
        int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (442  / 2);
1167
 
        int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (340  / 2);
1168
 
        skin_center->move(w_x, w_y);
1169
 
        skin_center->show();
1170
 
        skin_center->raise();
1171
 
    }
1172
 
    else {
1173
 
        int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (442  / 2);
1174
 
        int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (326  / 2);
1175
 
        skin_center->move(w_x, w_y);
1176
 
        skin_center->show();
1177
 
        skin_center->raise();
1178
 
    }
1179
 
}
1180
 
 
1181
 
void MainWindow::openUpgradePage(/*QStringList version_list*/)
1182
 
{
1183
 
    int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (334  / 2);
1184
 
    int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (470  / 2);
1185
 
    if(upgrade_dialog == NULL)
1186
 
    {
1187
 
//        upgrade_dialog = new UpgradeDialog(0, version_list.at(2), last_skin_path);
1188
 
        upgrade_dialog = new UpgradeDialog(0, /*this->version, */last_skin_path, this->arch, this->osName);//20161228
1189
 
        upgrade_dialog->setSystemDbusProxy(systeminterface);
1190
 
        upgrade_dialog->setSessionDbusProxy(sessioninterface);
1191
 
        connect(home_page, SIGNAL(sendOpenUpgrade()), this, SLOT(openUpgradePageAgain()));
1192
 
        connect(upgrade_dialog, SIGNAL(showBackendBtnSignal(bool)), home_page, SLOT(displayBackedBtn(bool)));
1193
 
        connect(upgrade_dialog,SIGNAL(close_signal()), this, SLOT(closeYoukerAssistant()));
1194
 
        connect(systeminterface,SIGNAL(get_fetch_signal(QString, QStringList)),upgrade_dialog,SLOT(receiveFetchSignal(QString, QStringList)));
1195
 
        connect(systeminterface,SIGNAL(get_apt_signal(QString, QStringList)),upgrade_dialog,SLOT(receiveAptSignal(QString, QStringList)));
1196
 
        connect(sessioninterface,SIGNAL(receive_source_list_signal(bool)),upgrade_dialog,SLOT(receiveCheckResultSignal(bool)));
1197
 
        upgrade_dialog->move(w_x, w_y);
1198
 
        upgrade_dialog->show();
1199
 
        upgrade_dialog->raise();
1200
 
        upgrade_dialog->startAccessData();
1201
 
    }
1202
 
    else {
1203
 
//        upgrade_dialog->resetVersionNumber(version_list);
1204
 
        upgrade_dialog->move(w_x, w_y);
1205
 
        upgrade_dialog->show();
1206
 
        upgrade_dialog->raise();
1207
 
        home_page->hideBackedBtn();
1208
 
//        upgrade_dialog->startAccessData();
1209
 
    }
1210
 
}
1211
 
 
1212
 
void MainWindow::openUpgradePageAgain()
1213
 
{
1214
 
    int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (334  / 2);
1215
 
    int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (470  / 2);
1216
 
    upgrade_dialog->move(w_x, w_y);
1217
 
    upgrade_dialog->show();
1218
 
    upgrade_dialog->raise();
1219
 
}
1220
 
 
1221
 
void MainWindow::displaySubPage(int index)
1222
 
{
1223
 
    if(index == 0)
1224
 
    {
1225
 
        if(auto_start == NULL) {
1226
 
            auto_start = new AutoStartWidget(0, sessioninterface, last_skin_path);
1227
 
            connect(sessioninterface, SIGNAL(tellAutoModel(QStringList)), auto_start, SLOT(readyReciveData(QStringList)));
1228
 
            connect(sessioninterface, SIGNAL(showAutoModel()), auto_start, SLOT(readyShowUI()));
1229
 
            auto_start->initData();
1230
 
            int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (560  / 2);
1231
 
            int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (398  / 2);
1232
 
            auto_start->move(w_x, w_y);
1233
 
            auto_start->show();
1234
 
            auto_start->raise();
1235
 
        }
1236
 
        else {
1237
 
            int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (560  / 2);
1238
 
            int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (398  / 2);
1239
 
            auto_start->move(w_x, w_y);
1240
 
            auto_start->show();
1241
 
            auto_start->raise();
1242
 
        }
1243
 
    }
1244
 
 
1245
 
    else if(index == 1)
1246
 
    {
1247
 
        //CameraManager *camera_manager = new CameraManager(0, sessioninterface, last_skin_path);
1248
 
        //int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (622  / 2);
1249
 
        //int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (480  / 2);
1250
 
        //camera_manager->move(w_x, w_y);
1251
 
        //camera_manager->exec();
1252
 
//        if(camera_manager == NULL) {
1253
 
//            camera_manager = new CameraManager(0, sessioninterface, last_skin_path);
1254
 
//            int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (622  / 2);
1255
 
//            int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (480  / 2);
1256
 
//            camera_manager->move(w_x, w_y);
1257
 
//            camera_manager->exec();
1258
 
//        }
1259
 
//        else {
1260
 
//            int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (622  / 2);
1261
 
//            int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (480  / 2);
1262
 
//            camera_manager->move(w_x, w_y);
1263
 
//            camera_manager->exec();
1264
 
//        }
1265
 
    }
1266
 
}
1267
 
 
1268
 
void MainWindow::newFeatures()
1269
 
{
1270
 
 
1271
 
}
1272
 
 
1273
 
void MainWindow::setupConfigure()
1274
 
{
1275
 
 
1276
 
}
1277
 
 
1278
 
void MainWindow::aboutUs()
1279
 
{
1280
 
    int w_x = this->frameGeometry().topLeft().x() + (900 / 2) - (442  / 2);
1281
 
    int w_y = this->frameGeometry().topLeft().y() + (600 /2) - (326  / 2);
1282
 
    if(aboutDlg == NULL)
1283
 
    {
1284
 
        aboutDlg = new AboutDialog(0, /*version, */last_skin_path, this->arch, this->osName);
1285
 
        aboutDlg->move(w_x, w_y);
1286
 
        aboutDlg->show();
1287
 
        aboutDlg->raise();
1288
 
    }
1289
 
    else {
1290
 
        aboutDlg->move(w_x, w_y);
1291
 
        aboutDlg->show();
1292
 
        aboutDlg->raise();
1293
 
    }
1294
 
}
1295
 
 
1296
 
 
1297
 
void MainWindow::mousePressEvent(QMouseEvent *event)
1298
 
{
1299
 
//    if(event->button() == Qt::LeftButton)
1300
 
//    {
1301
 
//        mouse_press = true;
1302
 
//        drag_pos = event->globalPos() - this->frameGeometry().topLeft();
1303
 
//        event->accept();
1304
 
//    }
1305
 
    if(event->button() == Qt::LeftButton)
1306
 
    {
1307
 
        mouse_press = true;
1308
 
        drag_pos = event->globalPos() - pos();
1309
 
    }
1310
 
}
1311
 
 
1312
 
void MainWindow::mouseReleaseEvent(QMouseEvent *)
1313
 
{
1314
 
    mouse_press = false;
1315
 
    setWindowOpacity(1);
1316
 
}
1317
 
 
1318
 
void MainWindow::mouseMoveEvent(QMouseEvent *event)
1319
 
{
1320
 
    if(mouse_press)
1321
 
    {
1322
 
        QPoint move_pos = event->globalPos();
1323
 
        move(move_pos - drag_pos);
1324
 
        setWindowOpacity(0.9);
1325
 
//        event->accept();
1326
 
    }
1327
 
}
1328
 
 
1329
 
//void MainWindow::paintEvent(QPaintEvent *event)
1330
 
//{
1331
 
//    QPainterPath path;
1332
 
//    path.setFillRule(Qt::WindingFill);
1333
 
//    path.addRect(10, 10, this->width()-20, this->height()-20);
1334
 
 
1335
 
//    QPainter painter(this);
1336
 
//    painter.setRenderHint(QPainter::Antialiasing, true);
1337
 
//    painter.fillPath(path, QBrush(Qt::white));
1338
 
 
1339
 
//    QColor color(0, 0, 0, 50);
1340
 
//    for(int i=0; i<10; i++)
1341
 
//    {
1342
 
//        QPainterPath path;
1343
 
//        path.setFillRule(Qt::WindingFill);
1344
 
//        path.addRect(10-i, 10-i, this->width()-(10-i)*2, this->height()-(10-i)*2);
1345
 
//        color.setAlpha(150 - qSqrt(i)*50);
1346
 
//        painter.setPen(color);
1347
 
//        painter.drawPath(path);
1348
 
//    }
1349
 
//}