-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.cpp
88 lines (74 loc) · 1.89 KB
/
worker.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
#include "worker.h"
#include <QDebug>
#include <QDesktopServices>
#include <QDir>
#include <QUrl>
QPointer<Worker> Worker::INSTANCE = nullptr;
Worker *Worker::instance()
{
if (INSTANCE.isNull())
INSTANCE = new Worker;
return INSTANCE;
}
Worker::Worker(QObject *parent)
: QObject(parent)
, m_settings(
new QSettings(QDir::homePath() + "/.config/ice/user.ini", QSettings::IniFormat, this))
{
m_closeAction = m_settings->value("closeAction", 1).toString();
m_isAsk = m_settings->value("isAsk", 1).toString();
m_cookie = m_settings->value("cookie", "").toString();
}
QString Worker::getCookie()
{
return m_cookie;
}
void Worker::saveCookie(QString cookie)
{
if (!cookie.isEmpty()) {
QStringList cookieList = cookie.split(';');
foreach (QString cookieItem, cookieList) {
cookieItem = cookieItem.trimmed();
QList<QString> parts = cookieItem.split('=');
if (parts.length() == 2) {
QByteArray name = parts[0].trimmed().toUtf8();
QByteArray value = parts[1].trimmed().toUtf8();
if (name == "MUSIC_U") {
// 保存cookie到配置文件
setCookie(cookieItem);
return;
}
}
}
}
}
void Worker::setCookie(QString cookie)
{
m_cookie = cookie;
m_settings->setValue("cookie", m_cookie);
}
QString Worker::getCloseAction()
{
return m_closeAction;
}
QString Worker::getIsAsk()
{
return m_isAsk;
}
void Worker::setCloseAction(QString action)
{
m_closeAction = action;
m_settings->setValue("closeAction", m_closeAction);
}
void Worker::setIsAsk(QString action)
{
m_isAsk = action;
m_settings->setValue("isAsk", m_isAsk);
}
void Worker::openUrl(QString url)
{
if (url.isEmpty())
return;
QDesktopServices::openUrl(QUrl(url));
}
Worker::~Worker() {}