Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /******************************************************************* |
---|---|
2 | * findconfigdatajob.cpp |
3 | * Copyright 2011 Matthias Fuchs <mat69@gmx.net> |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as |
7 | * published by the Free Software Foundation; either version 2 of |
8 | * the License, or (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | * |
18 | ******************************************************************/ |
19 | |
20 | #include "findconfigdatajob.h" |
21 | |
22 | #include <KDebug> |
23 | #include <KIO/Job> |
24 | #include <KLocalizedString> |
25 | |
26 | FindConfigDataJob::FindConfigDataJob(const QString &productName, const KUrl &bugtrackerBaseUrl, QObject *parent) |
27 | : KJob(parent), |
28 | m_job(0), |
29 | m_url(bugtrackerBaseUrl) |
30 | { |
31 | m_url.addPath("config.cgi"); |
32 | m_url.addQueryItem("product", productName); |
33 | } |
34 | |
35 | FindConfigDataJob::~FindConfigDataJob() |
36 | { |
37 | if (m_job) { |
38 | m_job->kill(); |
39 | } |
40 | } |
41 | |
42 | void FindConfigDataJob::start() |
43 | { |
44 | m_job = KIO::storedGet(m_url, KIO::Reload, KIO::HideProgressInfo); |
45 | connect(m_job, SIGNAL(result(KJob*)), this, SLOT(receivedData(KJob*))); |
46 | connect(m_job, SIGNAL(infoMessage(KJob*,QString,QString)), this, SIGNAL(infoMessage(KJob*,QString,QString))); |
47 | connect(m_job, SIGNAL(warning(KJob*,QString,QString)), this, SIGNAL(warning(KJob*,QString,QString))); |
48 | |
49 | m_job->start(); |
50 | } |
51 | |
52 | QString FindConfigDataJob::errorString() const |
53 | { |
54 | return m_errorString; |
55 | } |
56 | |
57 | void FindConfigDataJob::receivedData(KJob *job) |
58 | { |
59 | Q_UNUSED(job); |
60 | |
61 | if (m_job->error()) { |
62 | setError(m_job->error()); |
63 | m_errorString = i18n("Failed to retrieve the config data."); |
64 | } else { |
65 | m_data = m_job->data(); |
66 | } |
67 | m_job = 0; |
68 | emitResult(); |
69 | } |
70 | |
71 | QStringList FindConfigDataJob::data(InformationType type) |
72 | { |
73 | QStringList result; |
74 | QString key; |
75 | |
76 | switch (type) { |
77 | case Version: |
78 | key = "version\\['[^\']+'\\]"; |
79 | break; |
80 | default: |
81 | Q_ASSERT(false); |
82 | break; |
83 | } |
84 | |
85 | QRegExp rx(key + " = \\[ (('[^\']+', )+) \\];"); |
86 | if (rx.indexIn(m_data) != -1) { |
87 | QString temp = rx.cap(1); |
88 | temp.remove( |
89 | temp.remove( |
90 | result = temp.split( |
91 | } |
92 | |
93 | kDebug() << "Found data for "+ key + |
94 | return result; |
95 | } |
96 | |
97 | #include "findconfigdatajob.moc" |
98 |
Warning: That file was not part of the compilation database. It may have many parsing errors.