Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
2c007993
Commit
2c007993
authored
15 years ago
by
Daniel Molkentin
Browse files
Options
Downloads
Patches
Plain Diff
Port RSS fetcher to QNetworkAccessManager.
Reviewed-By:
Alessandro Portale
<
alessandro.portale@nokia.com
>
parent
286b7ef1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/app/main.cpp
+5
-0
5 additions, 0 deletions
src/app/main.cpp
src/plugins/welcome/rssfetcher.cpp
+13
-27
13 additions, 27 deletions
src/plugins/welcome/rssfetcher.cpp
src/plugins/welcome/rssfetcher.h
+8
-8
8 additions, 8 deletions
src/plugins/welcome/rssfetcher.h
with
26 additions
and
35 deletions
src/app/main.cpp
+
5
−
0
View file @
2c007993
...
@@ -43,6 +43,8 @@
...
@@ -43,6 +43,8 @@
#include
<QtCore/QSettings>
#include
<QtCore/QSettings>
#include
<QtCore/QVariant>
#include
<QtCore/QVariant>
#include
<QtNetwork/QNetworkProxyFactory>
#include
<QtGui/QMessageBox>
#include
<QtGui/QMessageBox>
#include
<QtGui/QApplication>
#include
<QtGui/QApplication>
#include
<QtGui/QMainWindow>
#include
<QtGui/QMainWindow>
...
@@ -216,6 +218,9 @@ int main(int argc, char **argv)
...
@@ -216,6 +218,9 @@ int main(int argc, char **argv)
}
}
}
}
// Make sure we honor the system's proxy settings
QNetworkProxyFactory
::
setUseSystemConfiguration
(
true
);
// Load
// Load
ExtensionSystem
::
PluginManager
pluginManager
;
ExtensionSystem
::
PluginManager
pluginManager
;
pluginManager
.
setFileExtension
(
QLatin1String
(
"pluginspec"
));
pluginManager
.
setFileExtension
(
QLatin1String
(
"pluginspec"
));
...
...
This diff is collapsed.
Click to expand it.
src/plugins/welcome/rssfetcher.cpp
+
13
−
27
View file @
2c007993
...
@@ -32,7 +32,8 @@
...
@@ -32,7 +32,8 @@
#include
<QtCore/QLocale>
#include
<QtCore/QLocale>
#include
<QtGui/QDesktopServices>
#include
<QtGui/QDesktopServices>
#include
<QtGui/QLineEdit>
#include
<QtGui/QLineEdit>
#include
<QtNetwork/QHttp>
#include
<QtNetwork/QNetworkReply>
#include
<QtNetwork/QNetworkRequest>
#include
<QtNetwork/QNetworkProxyFactory>
#include
<QtNetwork/QNetworkProxyFactory>
#include
<coreplugin/coreconstants.h>
#include
<coreplugin/coreconstants.h>
...
@@ -111,45 +112,31 @@ static const QString getOsString()
...
@@ -111,45 +112,31 @@ static const QString getOsString()
RSSFetcher
::
RSSFetcher
(
int
maxItems
,
QObject
*
parent
)
RSSFetcher
::
RSSFetcher
(
int
maxItems
,
QObject
*
parent
)
:
QObject
(
parent
),
m_items
(
0
),
m_maxItems
(
maxItems
)
:
QObject
(
parent
),
m_items
(
0
),
m_maxItems
(
maxItems
)
{
{
connect
(
&
m_http
,
SIGNAL
(
readyRead
(
const
QHttpResponseHeader
&
)),
connect
(
&
m_networkAccessManager
,
SIGNAL
(
finished
(
QNetworkReply
*
)),
this
,
SLOT
(
readData
(
const
QHttpResponseHeader
&
)));
SLOT
(
fetchingFinished
(
QNetworkReply
*
)));
connect
(
&
m_http
,
SIGNAL
(
requestFinished
(
int
,
bool
)),
this
,
SLOT
(
finished
(
int
,
bool
)));
}
}
void
RSSFetcher
::
fetch
(
const
QUrl
&
url
)
void
RSSFetcher
::
fetch
(
const
QUrl
&
url
)
{
{
QList
<
QNetworkProxy
>
proxies
=
QNetworkProxyFactory
::
systemProxyForQuery
(
QNetworkProxyQuery
(
url
));
if
(
proxies
.
count
()
>
0
)
m_http
.
setProxy
(
proxies
.
first
());
m_http
.
setHost
(
url
.
host
());
QString
agentStr
=
QString
(
"Qt-Creator/%1 (QHttp %2; %3; %4; %5 bit)"
)
QString
agentStr
=
QString
(
"Qt-Creator/%1 (QHttp %2; %3; %4; %5 bit)"
)
.
arg
(
Core
::
Constants
::
IDE_VERSION_LONG
).
arg
(
qVersion
())
.
arg
(
Core
::
Constants
::
IDE_VERSION_LONG
).
arg
(
qVersion
())
.
arg
(
getOsString
()).
arg
(
QLocale
::
system
().
name
())
.
arg
(
getOsString
()).
arg
(
QLocale
::
system
().
name
())
.
arg
(
QSysInfo
::
WordSize
);
.
arg
(
QSysInfo
::
WordSize
);
QHttpRequestHeader
header
(
"GET"
,
url
.
path
());
QNetworkRequest
req
(
url
);
//qDebug() << agentStr;
req
.
setRawHeader
(
"User-Agent"
,
agentStr
.
toLatin1
());
header
.
setValue
(
"User-Agent"
,
agentStr
);
m_networkAccessManager
.
get
(
req
);
header
.
setValue
(
"Host"
,
url
.
host
());
m_connectionId
=
m_http
.
request
(
header
);
}
}
void
RSSFetcher
::
readData
(
const
QHttpResponseHeader
&
resp
)
void
RSSFetcher
::
fetchingFinished
(
QNetworkReply
*
reply
)
{
{
if
(
resp
.
statusCode
()
!=
200
)
bool
error
=
(
reply
->
error
()
!=
QNetworkReply
::
NoError
);
m_http
.
abort
();
if
(
!
error
)
{
else
{
m_xml
.
addData
(
reply
->
readAll
());
m_xml
.
addData
(
m_http
.
readAll
());
parseXml
();
parseXml
();
m_items
=
0
;
}
}
}
void
RSSFetcher
::
finished
(
int
id
,
bool
error
)
{
Q_UNUSED
(
id
)
m_items
=
0
;
emit
finished
(
error
);
emit
finished
(
error
);
reply
->
deleteLater
();
}
}
void
RSSFetcher
::
parseXml
()
void
RSSFetcher
::
parseXml
()
...
@@ -182,6 +169,5 @@ void RSSFetcher::parseXml()
...
@@ -182,6 +169,5 @@ void RSSFetcher::parseXml()
}
}
if
(
m_xml
.
error
()
&&
m_xml
.
error
()
!=
QXmlStreamReader
::
PrematureEndOfDocumentError
)
{
if
(
m_xml
.
error
()
&&
m_xml
.
error
()
!=
QXmlStreamReader
::
PrematureEndOfDocumentError
)
{
qWarning
()
<<
"XML ERROR:"
<<
m_xml
.
lineNumber
()
<<
": "
<<
m_xml
.
errorString
();
qWarning
()
<<
"XML ERROR:"
<<
m_xml
.
lineNumber
()
<<
": "
<<
m_xml
.
errorString
();
m_http
.
abort
();
}
}
}
}
This diff is collapsed.
Click to expand it.
src/plugins/welcome/rssfetcher.h
+
8
−
8
View file @
2c007993
...
@@ -32,7 +32,11 @@
...
@@ -32,7 +32,11 @@
#include
<QtCore/QUrl>
#include
<QtCore/QUrl>
#include
<QtCore/QXmlStreamReader>
#include
<QtCore/QXmlStreamReader>
#include
<QtNetwork/QHttp>
#include
<QtNetwork/QNetworkAccessManager>
QT_BEGIN_NAMESPACE
class
QNetworkReply
;
QT_END_NAMESPACE
namespace
Welcome
{
namespace
Welcome
{
namespace
Internal
{
namespace
Internal
{
...
@@ -45,14 +49,11 @@ public:
...
@@ -45,14 +49,11 @@ public:
signals:
signals:
void
newsItemReady
(
const
QString
&
title
,
const
QString
&
desciption
,
const
QString
&
url
);
void
newsItemReady
(
const
QString
&
title
,
const
QString
&
desciption
,
const
QString
&
url
);
void
finished
(
bool
error
);
public
slots
:
public
slots
:
void
fetchingFinished
(
QNetworkReply
*
reply
);
void
fetch
(
const
QUrl
&
url
);
void
fetch
(
const
QUrl
&
url
);
void
finished
(
int
id
,
bool
error
);
void
readData
(
const
QHttpResponseHeader
&
);
signals:
void
finished
(
bool
error
);
private:
private:
void
parseXml
();
void
parseXml
();
...
@@ -63,8 +64,7 @@ private:
...
@@ -63,8 +64,7 @@ private:
QString
m_descriptionString
;
QString
m_descriptionString
;
QString
m_titleString
;
QString
m_titleString
;
QHttp
m_http
;
QNetworkAccessManager
m_networkAccessManager
;
int
m_connectionId
;
int
m_items
;
int
m_items
;
int
m_maxItems
;
int
m_maxItems
;
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment