Window::Window()
{
AppVars::urlRSSlist << "http://rss.lemonde.fr/c/205/f/3050/index.rss";
AppVars::netManList<< new QNetworkAccessManager(this);
QObject::connect (AppVars
::netManList[0],
SIGNAL(finished
(QNetworkReply
*)),
this,
SLOT(downloadedRSSalaune
(QNetworkReply
*))) ;
for(int i=0;i<AppVars::urlRSSlist.size();i++){
qDebug
() <<
"enter for loop for i = "+QString::number(i
);
AppVars
::netManList[i
]->get
(QNetworkRequest
(QUrl(AppVars
::urlRSSlist[i
])));
}
}
void Window::downloadedRSSalaune(QNetworkReply* reply){
qDebug() << reply->errorString();
QList<QString> titleList;
QList<QString> linkList;
if(!(domfile->setContent(data))){
return;
}
QDomNode principalNode
= domfile
->documentElement
();
QDomNode channelNode
= principalNode.
namedItem("rss").
namedItem("channel");
int k = 0;
int i = 0;
while(k<10 && i<listItems.length()){
if(listItems.at(i).nodeName() == "item"){
qDebug() << listItems.at(i).namedItem("title").toElement().text();
titleList << listItems.at(i).namedItem("title").toElement().text();
linkList << listItems.at(i).namedItem("link").toElement().text();
++k;
}
++i;
}
firstInsert10ArticlesXML(titleList, linkList, "alaune");
tooltipInstantNews("DirectNews France","Les articles sont maintenant à jours.","");
}
void Window
::firstInsert10ArticlesXML(QList<QString> titles, QList<QString> links,
QString cat
) {
filepath.append("\\history.xml");
AppFiles::historyXML->setFileName(filepath);
if(!(AppFiles
::historyXML->open
(QIODevice::ReadOnly))){ return;
}
// QDomDocument to parse xml file
if(!(domfile->setContent(AppFiles::historyXML))){
return;
}
AppFiles::historyXML->close();
QList<QDomElement *> newItems;
for(int i = 0; i<10; i++){
newItems<<new
QDomElement(domfile
->createElement
("item"));
QDomElement titleSubItem
= domfile
->createElement
("title");
QDomText titleText
= domfile
->createTextNode
(titles
[i
]);
QDomElement linkSubItem
= domfile
->createElement
("link");
QDomText linkText
= domfile
->createTextNode
(links
[i
]);
titleSubItem.appendChild(titleText);
linkSubItem.appendChild(linkText);
newItems[i]->appendChild(titleSubItem);
newItems[i]->appendChild(linkSubItem);
}
QDomNode principalNode
= domfile
->documentElement
();
QDomNode catNode
= principalNode.
namedItem(cat
);
if(catNode.isNull())
return;
for(int i = 0; i<10; i++){
catNode.insertBefore(*newItems[i],catNode.firstChild());
}
QString write_doc
= domfile
->toString
();
if(!(AppFiles
::historyXML->open
(QIODevice::WriteOnly))){ return;
}
AppFiles::historyXML->resize(0);
stream << write_doc;
AppFiles::historyXML->close();
ReadXML();
}
void Window::ReadXML()
{
filepath.append("\\history.xml");
AppFiles::historyXML->setFileName(filepath);
if(!(AppFiles
::historyXML->open
(QIODevice::ReadOnly))){ return;
}
// QDomDocument to parse xml file
if(!(domfile->setContent(AppFiles::historyXML))){
return;
}
AppFiles::historyXML->close();
QDomNode principalNode
= domfile
->documentElement
();
QList<QDomNode> listNodes;
listNodes<<principalNode.namedItem("alaune")<<principalNode.namedItem("monde")<<principalNode.namedItem("politique")<<principalNode.namedItem("societesante")
<<principalNode.namedItem("economie")<<principalNode.namedItem("science")<<principalNode.namedItem("art")<<principalNode.namedItem("sport")
<<principalNode.namedItem("people");
for(int k=0;k<9;k++){
QDomNode item
= listNodes
[k
].
firstChild();
int i = 0;
while(!listNodes[k].isNull() && !item.isNull() && i<10){
//for each article found, enable the QAction, and attribute text and link
listArticles[k][i]->setEnabled(true);
QString titleTrunc
= item.
namedItem("title").
toElement().
text();
if(titleTrunc.size() > 50)
titleTrunc = titleTrunc.left(50).append("...");
listArticles[k][i]->setText(titleTrunc);
AppVars::listShortcuts[k][i] = item.namedItem("link").toElement().text();
++i;
item = item.nextSibling();
}
}
}
{
// recieved from getrssthread.cpp, show directly (no use of any xml file) the news and attribute system tray message link
sticon->setToolTip(categorie+" : \n"+title);
AppVars::shortcutMessage = url;
if(AppVars::NotifBool)
}
Window::Window()
{
AppVars::urlRSSlist << "http://rss.lemonde.fr/c/205/f/3050/index.rss";
AppVars::netManList<< new QNetworkAccessManager(this);
QObject::connect (AppVars::netManList[0], SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadedRSSalaune(QNetworkReply*))) ;
for(int i=0;i<AppVars::urlRSSlist.size();i++){
qDebug() << "enter for loop for i = "+QString::number(i);
AppVars::netManList[i]->get(QNetworkRequest(QUrl(AppVars::urlRSSlist[i])));
}
}
void Window::downloadedRSSalaune(QNetworkReply* reply){
qDebug() << reply->errorString();
QByteArray data =QByteArray(reply->readAll());
QList<QString> titleList;
QList<QString> linkList;
QDomDocument *domfile = new QDomDocument("alaune_xml");
if(!(domfile->setContent(data))){
return;
}
QDomNode principalNode = domfile->documentElement();
QDomNode channelNode = principalNode.namedItem("rss").namedItem("channel");
QDomNodeList listItems = channelNode.childNodes();
int k = 0;
int i = 0;
while(k<10 && i<listItems.length()){
if(listItems.at(i).nodeName() == "item"){
qDebug() << listItems.at(i).namedItem("title").toElement().text();
titleList << listItems.at(i).namedItem("title").toElement().text();
linkList << listItems.at(i).namedItem("link").toElement().text();
++k;
}
++i;
}
firstInsert10ArticlesXML(titleList, linkList, "alaune");
tooltipInstantNews("DirectNews France","Les articles sont maintenant à jours.","");
}
void Window::firstInsert10ArticlesXML(QList<QString> titles, QList<QString> links, QString cat)
{
QString filepath = QCoreApplication::applicationDirPath();
filepath.append("\\history.xml");
AppFiles::historyXML->setFileName(filepath);
if(!(AppFiles::historyXML->open(QIODevice::ReadOnly))){
return;
}
// QDomDocument to parse xml file
QDomDocument *domfile = new QDomDocument("history_xml");
if(!(domfile->setContent(AppFiles::historyXML))){
return;
}
AppFiles::historyXML->close();
QList<QDomElement *> newItems;
for(int i = 0; i<10; i++){
newItems<<new QDomElement(domfile->createElement("item"));
QDomElement titleSubItem = domfile->createElement("title");
QDomText titleText = domfile->createTextNode(titles[i]);
QDomElement linkSubItem = domfile->createElement("link");
QDomText linkText = domfile->createTextNode(links[i]);
titleSubItem.appendChild(titleText);
linkSubItem.appendChild(linkText);
newItems[i]->appendChild(titleSubItem);
newItems[i]->appendChild(linkSubItem);
}
QDomNode principalNode = domfile->documentElement();
QDomNode catNode = principalNode.namedItem(cat);
if(catNode.isNull())
return;
for(int i = 0; i<10; i++){
catNode.insertBefore(*newItems[i],catNode.firstChild());
}
QString write_doc = domfile->toString();
if(!(AppFiles::historyXML->open(QIODevice::WriteOnly))){
return;
}
AppFiles::historyXML->resize(0);
QTextStream stream(AppFiles::historyXML);
stream << write_doc;
AppFiles::historyXML->close();
ReadXML();
}
void Window::ReadXML()
{
QString filepath = QCoreApplication::applicationDirPath();
filepath.append("\\history.xml");
AppFiles::historyXML->setFileName(filepath);
if(!(AppFiles::historyXML->open(QIODevice::ReadOnly))){
return;
}
// QDomDocument to parse xml file
QDomDocument *domfile = new QDomDocument("history_xml");
if(!(domfile->setContent(AppFiles::historyXML))){
return;
}
AppFiles::historyXML->close();
QDomNode principalNode = domfile->documentElement();
QList<QDomNode> listNodes;
listNodes<<principalNode.namedItem("alaune")<<principalNode.namedItem("monde")<<principalNode.namedItem("politique")<<principalNode.namedItem("societesante")
<<principalNode.namedItem("economie")<<principalNode.namedItem("science")<<principalNode.namedItem("art")<<principalNode.namedItem("sport")
<<principalNode.namedItem("people");
for(int k=0;k<9;k++){
QDomNode item = listNodes[k].firstChild();
int i = 0;
while(!listNodes[k].isNull() && !item.isNull() && i<10){
//for each article found, enable the QAction, and attribute text and link
listArticles[k][i]->setEnabled(true);
QString titleTrunc = item.namedItem("title").toElement().text();
if(titleTrunc.size() > 50)
titleTrunc = titleTrunc.left(50).append("...");
listArticles[k][i]->setText(titleTrunc);
AppVars::listShortcuts[k][i] = item.namedItem("link").toElement().text();
++i;
item = item.nextSibling();
}
}
}
void Window::tooltipInstantNews(QString title, QString categorie, QString url)
{
// recieved from getrssthread.cpp, show directly (no use of any xml file) the news and attribute system tray message link
sticon->setToolTip(categorie+" : \n"+title);
AppVars::shortcutMessage = url;
if(AppVars::NotifBool)
sticon->showMessage(categorie,title,QSystemTrayIcon::Information);
}
To copy to clipboard, switch view to plain text mode
Bookmarks