bool Archive::Open(std::string filename,bool bWriteMode) { if (Loading() || Saving()) Close(); this->bWriteMode = bWriteMode; this->bTextMode = Utils::ToLower(filename).find(".xml")!=std::string::npos; bool bZip = Utils::ToLower(filename).find( ".gz")!=std::string::npos; std::string smode=std::string(bWriteMode?"w":"r") + std::string((bTextMode && !bZip)?"t":"b") ; this->file=0; this->gzfile=0; if (!bZip) { this->file=fopen(filename.c_str(),smode.c_str()); if (!this->file) return false; } else { this->gzfile=gzopen(filename.c_str(),smode.c_str()); if (!this->gzfile) return false; } //if xml output, prepare the XML document if (bTextMode) { TiXmlDocument* xml_doc =new TiXmlDocument; if (Saving()) { xml_doc->LinkEndChild( new TiXmlDeclaration( "1.0", "", "" ) ); xml_doc->LinkEndChild( new TiXmlElement("root") ); } if (Loading()) { unsigned long filesize; unsigned char* content=FileSystem::ReadFile(filename.c_str(),filesize,true); if (!xml_doc->Parse((const char*)content)) { Log::printf("Failed of open_xml for file %s ErrorRow(%d) ErrorCol(%d) ErrorDesc(%s)",filename.c_str(),(int)xml_doc->ErrorRow(),(int)xml_doc->ErrorCol(),xml_doc->ErrorDesc()); Close(); return false; } } StackItem stack_doc ={"xml_doc",xml_doc ,0};xml_objects.push(stack_doc ); StackItem stack_root={"root" ,xml_doc->FirstChildElement("root"),0};xml_objects.push(stack_root); } return true; }
void RSSEditPopup::ParseAndSave(void) { if (m_editing) { QString title = m_titleEdit->GetText(); QString desc = m_descEdit->GetText(); QString author = m_authorEdit->GetText(); QString link = m_urlEdit->GetText(); QString filename = m_thumbImage->GetFilename(); bool download; if (m_download->GetCheckState() == MythUIStateType::Full) download = true; else download = false; removeFromDB(m_urlText, VIDEO_PODCAST); RSSSite site(title, filename, VIDEO_PODCAST, desc, link, author, download, MythDate::current()); if (insertInDB(&site)) emit Saving(); Close(); } else { m_manager = new QNetworkAccessManager(); QUrl qurl(m_urlEdit->GetText()); m_reply = m_manager->get(QNetworkRequest(qurl)); connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(SlotCheckRedirect(QNetworkReply*))); } }
void Archive::Close() { //destroy the xml root (if exists) if (xml_objects.size()) { //take the document to deallocate it while (xml_objects.size()!=1) xml_objects.pop(); TiXmlDocument* xml_doc=CURNODE->ToDocument(); //close the file (==save it) if (Saving()) { TiXmlPrinter printer; printer.SetIndent("\t"); xml_doc->Accept(&printer); const char* content= printer.CStr(); int len=(int)strlen(content)+1; bTextMode=false; //want the output to the real file InnerWrite((void*)content,len); } delete xml_doc; } xml_objects=std::stack<StackItem >(); //destry the map for SmartPointer Objects if (this->Loading()) { for (std::map<uint64,uint64>::iterator it=smart_pointers.begin();it!=smart_pointers.end();it++) { //see: http://www.boost.org/doc/libs/1_40_0/libs/smart_ptr/sp_techniques.html#preventing_delete //Interesting part: Using shared_ptr<void> to hold an arbitrary object //Checked and it seems to work (probably shared_ptr probably stores inside the correct deleter!) SmartPointer<void>* temp=(SmartPointer<void>*)(it->second); temp->reset(); delete temp; } } smart_pointers.clear(); //close the gzfile if (this->gzfile) gzclose((gzFile)this->gzfile); this->gzfile=0; //close the regular file if (this->file) fclose(this->file); this->file=0; }
void XHCIOpRegister::HCSave() { if(!IsHCHalted()) throw upan::exception(XLOC, "Cannot Save while HC is not halted"); if(Saving()) throw upan::exception(XLOC, "Cannot initiate save while save is in-progress"); if(Restoring()) throw upan::exception(XLOC, "Cannot initiate save while restore is in-progress"); _usbCmd |= 0x100; ProcessManager::Instance().Sleep(20); if(!ProcessManager::Instance().ConditionalWait(&_usbStatus, 8, false)) throw upan::exception(XLOC, "HC Save didn't complete - timedout"); }
void RSSEditor::SlotNewSite() { QMutexLocker locker(&m_lock); MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); RSSEditPopup *rsseditpopup = new RSSEditPopup("", false, mainStack, "rsseditpopup"); if (rsseditpopup->Create()) { connect(rsseditpopup, SIGNAL(Saving()), this, SLOT(ListChanged())); mainStack->AddScreen(rsseditpopup); } else delete rsseditpopup; }
void RSSEditor::SlotEditSite() { QMutexLocker locker(&m_lock); MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); RSSSite *site = m_sites->GetItemCurrent()->GetData().value<RSSSite*>(); if (site) { RSSEditPopup *rsseditpopup = new RSSEditPopup(site->GetURL(), true, mainStack, "rsseditpopup"); if (rsseditpopup->Create()) { connect(rsseditpopup, SIGNAL(Saving()), this, SLOT(ListChanged())); mainStack->AddScreen(rsseditpopup); } else delete rsseditpopup; } }
void Archive::Push(std::string name) { if (bTextMode && Saving()) { TiXmlElement * xml_element = new TiXmlElement(name.c_str()); CURNODE->LinkEndChild(xml_element); StackItem stack_item={name,xml_element,0}; xml_objects.push(stack_item); return; } if (bTextMode && Loading()) { StackItem& current=xml_objects.top(); TiXmlNode* xml_child=((TiXmlNode*)current.first)->IterateChildren((TiXmlNode*)current.second); current.second=xml_child; StackItem stack_item={name,xml_child,0}; xml_objects.push(stack_item); return; } }
void RSSEditPopup::SlotSave(QNetworkReply* reply) { QDomDocument document; document.setContent(reply->read(reply->bytesAvailable()), true); QString text = document.toString(); QString title = m_titleEdit->GetText(); QString description = m_descEdit->GetText(); QString author = m_authorEdit->GetText(); QString file = m_thumbImage->GetFilename(); LOG(VB_GENERAL, LOG_DEBUG, QString("Text to Parse: %1").arg(text)); QDomElement root = document.documentElement(); QDomElement channel = root.firstChildElement ("channel"); if (!channel.isNull()) { Parse parser; if (title.isEmpty()) title = channel.firstChildElement("title").text().trimmed(); if (description.isEmpty()) description = channel.firstChildElement("description").text(); if (author.isEmpty()) author = parser.GetAuthor(channel); if (author.isEmpty()) author = channel.firstChildElement("managingEditor").text(); if (author.isEmpty()) author = channel.firstChildElement("webMaster").text(); QString thumbnailURL = channel.firstChildElement("image").attribute("url"); if (thumbnailURL.isEmpty()) { QDomElement thumbElem = channel.firstChildElement("image"); if (!thumbElem.isNull()) thumbnailURL = thumbElem.firstChildElement("url").text(); } if (thumbnailURL.isEmpty()) { QDomNodeList nodes = channel.elementsByTagNameNS( "http://www.itunes.com/dtds/podcast-1.0.dtd", "image"); if (nodes.size()) { thumbnailURL = nodes.at(0).toElement().attributeNode("href").value(); if (thumbnailURL.isEmpty()) thumbnailURL = nodes.at(0).toElement().text(); } } bool download; if (m_download->GetCheckState() == MythUIStateType::Full) download = true; else download = false; QDateTime updated = MythDate::current(); QString filename(""); if (!file.isEmpty()) filename = file; else if (!thumbnailURL.isEmpty()) filename = thumbnailURL; QString link = m_urlEdit->GetText(); RSSSite site(title, filename, VIDEO_PODCAST, description, link, author, download, MythDate::current()); if (insertInDB(&site)) emit Saving(); } Close(); }
Archive::~Archive() { if (Saving() || Loading()) this->Close(); }