bool pEditor::openFile( const QString& fileName, const QString& codec ) { /*if ( isModified() ) return false;*/ QApplication::setOverrideCursor( Qt::WaitCursor ); // open file QFile f( fileName ); if ( !f.open( QFile::ReadOnly ) ) { MonkeyCore::messageManager()->appendMessage( tr( "Cannot read file %1:\n%2." ).arg( fileName ).arg( f.errorString() ) ); QApplication::restoreOverrideCursor(); return false; } // remember filename setProperty( "fileName", fileName ); setProperty( "codec", codec ); // set lexer and apis setLexer( pMonkeyStudio::lexerForFileName( fileName ) ); // set properties pMonkeyStudio::setEditorProperties( this ); // load file QTextCodec* c = QTextCodec::codecForName( codec.toUtf8() ); QString datas = c->toUnicode( f.readAll() ); setText( datas ); setModified( false ); // convert tabs if needed if ( pMonkeyStudio::convertTabsUponOpen() ) convertTabs(); //autodetect indent, if need if ( pMonkeyStudio::autoDetectIndent() ) { autoDetectIndent (); } //autodetect eol, if need if ( pMonkeyStudio::autoDetectEol() ) { autoDetectEol(); } // make backup if needed if ( pMonkeyStudio::createBackupUponOpen() ) makeBackup(); // convert eol if ( pMonkeyStudio::autoEolConversion() ) convertEols( eolMode() ); QApplication::restoreOverrideCursor(); return true; }
void FileLog::logString( char *inLoggerName, char *inString, int inLevel ) { if( mLogFile != NULL ) { if( inLevel <= mLoggingLevel ) { char *message = PrintLog::generateLogMessage( inLoggerName, inString, inLevel ); mLock->lock(); fprintf( mLogFile, "%s\n", message ); fflush( mLogFile ); if( time( NULL ) - mTimeOfLastBackup > mSecondsBetweenBackups ) { makeBackup(); } mLock->unlock(); delete [] message; } } }
void TTRssFetcher::startFetching() { auto s = Settings::instance(); auto db = DatabaseManager::instance(); if (!db->makeBackup ()) { qWarning() << "Unable to make DB backup"; emit error(506); setBusy(false); return; } db->cleanDashboards(); DatabaseManager::Dashboard d; d.id = "ttrss"; d.name = "Default"; d.title = "Default"; d.description = "Tiny Tiny Rss default dashboard"; db->writeDashboard(d); s->setDashboardInUse(d.id); db->cleanTabs(); db->cleanStreams(); db->cleanModules(); if(busyType == Fetcher::Initiating) { db->cleanCache(); db->cleanEntries(); } commandList.clear(); commandList.append(&TTRssFetcher::fetchCategories); commandList.append(&TTRssFetcher::fetchFeeds); commandList.append(&TTRssFetcher::fetchStream); commandList.append(&TTRssFetcher::fetchStarredStream); commandList.append(&TTRssFetcher::fetchPublishedStream); commandList.append(&TTRssFetcher::pruneOld); proggressTotal = commandList.size() + s->getRetentionDays(); proggress = 0; lastDate = 0; offset = 0; callNextCmd(); }
void AdminDatabase::addButtonClicked() { // pg_dump -h localhost -U kladmin kludoteca std::cout << "Making backup..." << std::endl; if ( m_havePgDump ) { QTimer::singleShot(50, this, SLOT(makeBackup())); } else { QString error = ""; if ( ! m_havePgDump ) error += "You doesn't have the command pg_dump\n"; // if ( !m_havePsql) // error += "You doesn't have the command psql\n"; KMessageBox::detailedSorry (0, i18n("I can't backup the database!"), error); } }
void TPicturesProject::save() const { makeBackup(); QFile goodDatFile(dir.absoluteFilePath(QString("good.dat"))); goodDatFile.open(QIODevice::WriteOnly); QTextStream stream(&goodDatFile); for (TMarkedPictures::const_iterator it = markedPictures.begin(); it != markedPictures.end(); ++it) { const TMarkedPicture & picture = *it; stream << "good/" << picture.name << " "; const size_t objectCount = picture.objects.size(); stream << objectCount; for (size_t i = 0; i < objectCount; ++i) { const QRect & rect = picture.objects[i]; stream << " " << rect.left() << " " << rect.top() << " " << rect.width() << " " << rect.height(); } stream << "\n"; } }
void Bank::save( const string& p, bool saveCurrent, bool backup ) { string path = p.empty() ? path_ : p; if( path.empty() ) return; if( saveCurrent ) saveCurrentProgram(); if( backup ) makeBackup(); Document doc; Declaration* declaration = new Declaration( "1.0", "", "no" ); doc.LinkEndChild( declaration ); Element* bankElement = new Element( "Bank" ); bankElement->SetAttribute( "name", name_ ); bankElement->SetAttribute( "program", programNum_ ); for( UINT32 i=0; i<size(); i++ ) { Program* program = at( i ); if( program->empty() == false ) { Element* programElement = writeProgram( program ); bankElement->LinkEndChild( programElement ); } } doc.LinkEndChild( bankElement ); try { doc.SaveFile( path ); path_ = path; } catch( const exception& e ) { TRACE( e.what() ); } doc.Clear(); }
void PlaylistComponent::saveTemporaryTree(bool * const cancelled) { treeWidget_.assertValidTemporaryTree(); temporaryTree_->nodesChanged(); if (treeAutoCleanup_) temporaryTree_->cleanUp(); const bool backedUp = makeBackup(); QtUtilities::Widgets::HandleErrors handleErrors { [&] { QtUtilities::makePathTo(qItemsFilename_); if (temporaryTree_->save(itemsFilename_)) return QString(); if (backedUp) restoreBackup(); return savingFailed(); } }; if (cancelled == nullptr) handleErrors.nonBlocking(); else handleErrors.blocking(inputController_, ioError(), cancelled); }