File: ukccabout.cpp

package info (click to toggle)
ukui-control-center 3.22.1.29-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,420 kB
  • sloc: cpp: 77,963; xml: 2,408; sh: 30; makefile: 4
file content (129 lines) | stat: -rw-r--r-- 3,656 bytes parent folder | download
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
/*
 * Copyright (C) 2023, KylinSoft Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
**/
#include "ukccabout.h"
#include "xatom-helper.h"
#include "interface/ukcccommon.h"

#include <QVariant>
#include <QDesktopServices>
#include <QUrl>
#include <QMouseEvent>
#include <QDebug>

UkccAbout::UkccAbout(QWidget *parent)
    : QDialog(parent) {

    setFixedSize(420, 344);
    setWindowTitle(tr("Settings"));
    initUI();
    hideComponent();
}

bool UkccAbout::eventFilter(QObject *watch, QEvent *event)
{
    if ( watch == mTipLabel_2) {
        if (event->type() == QEvent::MouseButtonPress){
            QMouseEvent * mouseEvent = static_cast<QMouseEvent *>(event);
            if (mouseEvent->button() == Qt::LeftButton){
                QDesktopServices::openUrl(QUrl(QLatin1String("mailto:support@kylinos.cn")));
            }
        }
    }
    return QDialog::eventFilter(watch, event);
}

void UkccAbout::initUI() {
    QVBoxLayout *Lyt = new QVBoxLayout(this);
    Lyt->setContentsMargins(40, 32, 32, 32);
    Lyt->setSpacing(16);

    mIconLabel = new QLabel(this);
    mIconLabel->setFixedSize(96, 96);
    mIconLabel->setPixmap(QIcon::fromTheme("ukui-control-center").pixmap(96, 96));

    mAppLabel = new QLabel(tr("Settings"),this);
    mAppLabel->setStyleSheet("QLabel{font-size: 18px; font-weight: bold}");

    QHBoxLayout *Lyt_1 = new QHBoxLayout();
    Lyt_1->setSpacing(0);
    mVersionLabel_1 = new LightLabel(tr("Version: "), this);
    mVersionLabel_2 = new LightLabel(getUkccVersion(), this);

    Lyt_1->addStretch();
    Lyt_1->addWidget(mVersionLabel_1);
    Lyt_1->addWidget(mVersionLabel_2);
    Lyt_1->addStretch();

    QHBoxLayout *Lyt_2 = new QHBoxLayout();
    Lyt_2->setSpacing(8);
    mTipLabel_1 = new LightLabel(tr("Service and Support:"), this);
    mTipLabel_2 = new LightLabel("support@kylinos.cn", this);
    mTipLabel_2->setStyleSheet("LightLabel{text-decoration: underline}");
    mTipLabel_2->installEventFilter(this);

    Lyt_2->addStretch();
    Lyt_2->addWidget(mTipLabel_1);
    Lyt_2->addWidget(mTipLabel_2);
    Lyt_2->addStretch();

    Lyt->addWidget(mIconLabel, 0, Qt::AlignHCenter);
    Lyt->addSpacing(8);
    Lyt->addWidget(mAppLabel, 0, Qt::AlignHCenter);
    Lyt->addLayout(Lyt_1);
    Lyt->addLayout(Lyt_2);
    Lyt->addStretch();
}

void UkccAbout::hideComponent()
{
#ifdef OPENKYLIN
    mTipLabel_1->hide();
    mTipLabel_2->hide();
#endif
}

QString UkccAbout::getUkccVersion() {
    FILE *pp = NULL;
    char *line = NULL;
    size_t len = 0;
    ssize_t read;
    char *q = NULL;
    QString version = "none";

    pp = popen("dpkg -l  ukui-control-center | grep  ukui-control-center", "r");
    if(NULL == pp)
        return version;

    while((read = getline(&line, &len, pp)) != -1){
        q = strrchr(line, '\n');
        *q = '\0';

        QString content = line;
        QStringList list = content.split(" ");

        list.removeAll("");

        if (list.size() >= 3)
            version = list.at(2);
    }

    free(line);
    line = NULL;
    pclose(pp);
    return version;
}