⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newsreader.cpp

📁 this program is Newsreader using RSS (XML) base on Qt app
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   // if ( !News_listView1->firstChild() )   //     return;         QFile f( "Store.txt" );    if ( !f.open(IO_WriteOnly | IO_Append) )        return;    QTextStream t( &f );    t.setEncoding(QTextStream::UnicodeUTF8);    for(int i = 0 ; i <= 50; i++){News_progressBar2->setProgress(i);}     QListViewItemIterator it( News_listView1 );    while ( it.current() ) {        for ( unsigned int i = 0; i < 3; i++ ){	     if ( it.current()->isSelected() )	      {               t << it.current()->text( i );               if(i != 2)			t << "^";               if(i == 2)                    t << "\n";              }	  }        ++it;     }    f.close();	for(int i = 50 ; i <= 100; i++){News_progressBar2->setProgress(i);} }void NewsReader::ShowNewsContent() //뉴스 내용 보여주기 위한 함수{	Browser_textEdit1->setText("");	BrowserList->show();	///////////선택된 아이템의 값을 가져오는 부분//////////  /*    QListViewItemIterator it( News_listView1 );      while ( it.current() ) {         	       if ( it.current()->isSelected() )	        {                 Backup[1]=it.current()->text(1);  	          break;                 }            ++it;       }*/ 	//DirectoryView dv = new DirectoryView(News_listView1);	Backup[1] = News_listView1->currentItem()->text(1);	Backup[3] = News_listView1->currentItem()->text(0);       ////////////////////////////////////////////////////////       QUrl url(Backup[1]);	http->setHost(url.host(), (url.port() != -1)?url.port():80);	http->get(url.toString());	//usleep(7000);   	for(int i = 0 ; i <= 30; i++)	{		Browser_progressBar2->setProgress(i);	}		browserint = true;	connect(http, SIGNAL(done(bool)),this,SLOT(loadDone(bool)));}void NewsReader::ShowNewsContent1() //보관함의 내용을 보여주기 위한 함수{	Browser_textEdit1->setText("");	BrowserList->show();	///////////선택된 아이템의 값을 가져오는 부분//////////   //   QListViewItemIterator it( Store_listView1 );//      while ( it.current() ) {         //	       if ( it.current()->isSelected() )//	        {//                 Backup[1]=it.current()->text(1);  //	          break; //                }  //         ++it;//       }	Backup[1] = Store_listView1->currentItem()->text(1);	Backup[3] = Store_listView1->currentItem()->text(0);       ////////////////////////////////////////////////////////	//QMessageBox::critical( 0,tr( "Critical Error" ),tr( "Cannot open file %1" ).arg( Backup[1] ) );       QUrl url(Backup[1]);	http->setHost(url.host(), (url.port() != -1)?url.port():80);	http->get(url.toString());	//usleep(7000); 	for(int i = 0 ; i <= 30; i++)	{		Browser_progressBar2->setProgress(i);	}  	browserint = true;	connect(http, SIGNAL(done(bool)),this,SLOT(loadDone(bool)));}int NewsReader::loadDone(bool error){	QString Temp = toUniString(http->readAll());		int a;	int b;		a = Temp.findRev("BODY START");	b = Temp.findRev("BODY END");	if( a == -1 || b == -1)	{		//connect(http, SIGNAL(done(bool)),this,SLOT(loadDone(bool)));		for(int i = 50 ; i <= 100; i++)		{			Browser_progressBar2->setProgress(i);		}		return 0;	}else{		LastTemp = Temp.mid( a+14 , b-a-14 );		////////////////////////test 		//QString c = QString("%d Number %d %d");		//c.arg(a);		//c.arg(b);		/////////////////////////////////end test		//// to search is failed  		for(int i = 30 ; i <= 50; i++)		{			Browser_progressBar2->setProgress(i);		}			QString imgstr = LastTemp;		int imga;		int imgb;		for(int cnt = 0 ; cnt <= 100; cnt++){			/////////////////image path parsing			imga = imgstr.find("src=");			imgb = imgstr.find(QRegExp("jpg|gif"));			if(imga == -1 || imgb == -1) break;			QString imgpath = imgstr.mid(imga+4,imgb-imga-1);			imgstr = imgstr.mid(imgb+4,imgstr.length() - imgb-4);						QUrl imgurl(imgpath);			//Browser_textEdit1->append(imgpath);						/////////////////image download			QFileInfo fileInfo(imgurl.path());			QString fileName = fileInfo.fileName();				/*			QFile * file = new QFile(fileName);			http->setHost(imgurl.host(), imgurl.port() != -1 ? imgurl.port() : 80);			    	http->get(imgurl.path(),file);	*/						if (browserint == true)			{				QUrlOperator *op;				op = new QUrlOperator();				op->copy( QString(imgpath), "./" );					connect(op,SIGNAL(finished(QNetworkOperation*)),this,SLOT(slotFinished(QNetworkOperation*)));			}			QMimeSourceFactory::defaultFactory()->setImage( fileName, QImage(fileName) );			LastTemp.replace(imgpath,"\"" + fileName + "\"" );			//QMimeSourceFactory::defaultFactory()->setImage( fileName, QImage(fileName) );		}		for(int i = 50 ; i <= 80; i++)		{			Browser_progressBar2->setProgress(i);		}		//QMessageBox::information(this,"Information",list[0]);	    	Browser_textEdit1->setText("<html><body><center><b>[" + Backup[3]+"]</b></center><br>" + LastTemp + "</body></html>" );		for(int i = 80 ; i <= 100; i++)		{			Browser_progressBar2->setProgress(i);		}	}		return 0;}void NewsReader::slotFinished(QNetworkOperation* pOp){         if(!pOp)                 return;         if(pOp && pOp->state() == QNetworkProtocol::StFailed)         {                 QMessageBox::warning(0, "Network Operation", "Failed to retrieve page");         }         else         {			//QMessageBox::warning(0, "Network Operation", "Failed to retrieve page");		       QUrl url(Backup[1]);			http->setHost(url.host(), (url.port() != -1)?url.port():80);			http->get(url.toString());			//usleep(7000); 			for(int i = 0 ; i <= 30; i++)			{				Browser_progressBar2->setProgress(i);			}  			browserint = false;			connect(http, SIGNAL(done(bool)),this,SLOT(loadDone(bool)));                          }}void NewsReader::BrowserZoomin(){	Browser_textEdit1->zoomIn();}void NewsReader::BrowserZoomout(){	Browser_textEdit1->zoomOut();}void NewsReader::ShowNewsTitle(){    NewsList->show();      News_listView1->clear();     QUrl url(temp[Update_listBox2->currentItem()]);	    QFileInfo fileInfo(url.path());   QString fileName = fileInfo.fileName();    QFile opmlFile( fileName );    if ( !opmlFile.open( IO_ReadOnly ) ) {	QMessageBox::critical( 0,		tr( "Critical Error" ),		tr( "Cannot open file %1" ).arg( fileName ) );	return;    }    if ( !domTree.setContent( &opmlFile ) ) {	QMessageBox::critical( 0,	tr( "Critical Error" ),		tr( "Parsing error for file %1" ).arg( fileName ) );	opmlFile.close();	return;    }    opmlFile.close();    // get the header information from the DOM    QDomElement root = domTree.documentElement();    QDomNode node;    // create the tree view out of the DOM  channel    node = root.firstChild();    while ( !node.isNull() ) {	if ( node.isElement() && node.nodeName() == "channel" ) {	    QDomElement channel = node.toElement();		QDomNode node1 = channel.firstChild();		while ( !node1.isNull() ) {			if ( node1.isElement() && node1.nodeName() == "item" ) {			    QDomElement channel1 = node1.toElement();				//QMessageBox::information(this,"Information",channel.tagName());				ShowNewsSub(channel1 );			}			node1 = node1.nextSibling();		}			}	node = node.nextSibling();    }}void NewsReader::ShowNewsSub(const QDomElement &parentElement){    QListViewItem *thisItem = 0;       QDomNode node = parentElement.firstChild();    thisItem = new QListViewItem( News_listView1, thisItem );	while ( !node.isNull() ) {	if ( node.isElement() && node.nodeName() == "title" ) {		QDomText textChild = node.firstChild().toText();          // thisItem = new QListViewItem(listview1, textChild.nodeValue(), "1");	       thisItem->setText( 0,  textChild.nodeValue());	}	if ( node.isElement() && node.nodeName() == "link" ) {	   	QDomText textChild = node.firstChild().toText();		thisItem->setText( 1, textChild.nodeValue() );	}	if ( node.isElement() && node.nodeName() == "pubDate" ) {	   	QDomText textChild = node.firstChild().toText();		thisItem->setText( 2, textChild.nodeValue() );	}	node = node.nextSibling();    }}void NewsReader::pressXmlUpdate(){	QUrlOperator *op;		for(int i=0; i<=15; i++)	{				 op = new QUrlOperator();		 op->copy( QString(temp[i]), "./" );             Update_progressBar2->setProgress(i*4);	} 	Update_progressBar2->setProgress(100);}void NewsReader::UpdateShow(){	MainFrame->hide();	BrowserList->hide();      NewsList->hide();      UpdateList->show();	StoreList->hide();       Update_listBox2->clear();	QString fileName = "xml/list.xml";	QFile opmlFile( fileName );	if ( !opmlFile.open( IO_ReadOnly ) ) {		QMessageBox::critical( 0,			tr( "Critical Error" ),			tr( "Cannot open file %1" ).arg( fileName ) );		return;	}	if ( !domTree.setContent( &opmlFile ) ) {		QMessageBox::critical( 0,			tr( "Critical Error" ),			tr( "Parsing error for file %1" ).arg( fileName ) );		opmlFile.close();		return;	}		    opmlFile.close();	    domTree.setContent(&opmlFile);	    QDomElement root = domTree.documentElement();	    QDomNode node; 	    node = root.firstChild();	    while ( !node.isNull() ) {		if ( node.isElement() && node.nodeName() == "body" ) {		    QDomElement body = node.toElement();		    buildTree(body);		    break;		}		node = node.nextSibling();	    }}void NewsReader::NewsShow(){	MainFrame->hide();	BrowserList->hide();      NewsList->show();      UpdateList->hide();	StoreList->hide();}void NewsReader::StoreShow(){	MainFrame->hide();	BrowserList->hide();      NewsList->hide();      UpdateList->hide();	StoreList->show();	browserint = true;}void NewsReader::BrowserShow(){	MainFrame->hide();	BrowserList->show();      NewsList->hide();      UpdateList->hide();	StoreList->hide();}QString toUniString(QString str){    QTextCodec * codec = QTextCodec::codecForName("eucKR");    QString localeStr = codec->toUnicode(str);    return localeStr;}void NewsReader::buildTree(const QDomElement &parentElement ){    int i = 0;        QDomNode node = parentElement.firstChild();    while ( !node.isNull() ) {        if ( node.isElement() && node.nodeName() == "outline" ) {                Update_listBox2->insertItem(kor(node.toElement().attribute("title")),i);	      temp[i] = node.toElement().attribute("link");            buildTree(node.toElement());        }        node = node.nextSibling();      i++;    }}int main(int argc, char ** argv){    QApplication QApp(argc, argv);    QFont font("back", 15);    QApp.setFont(font);    NewsReader News;    QApp.setMainWidget(&News);    News.show();	    return QApp.exec();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -