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

📄 qmrecoverymanager.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
字号:
/* qmrecoverymanager.cpp * * $Id: qmrecoverymanager.cpp,v 1.4.2.2 2002/10/11 06:39:03 kyllingstad Exp $ * * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team.  See CREDITS file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * The GNU General Public License is also available online at: * * http://www.gnu.org/copyleft/gpl.html */#include "qmrecoverymanager.h"#include "qmconfig.h"#include "qmrecoverydialog.h"#include <qfile.h>#include <qmessagebox.h>#include <qtextstream.h>#include <qglobal.h> // _WS_X11_ / _WS_WIN_ defines#ifdef OS_UNIX#include <errno.h>#include <sys/types.h>#include <signal.h>#include <unistd.h>#endif/*! \file qmrecoverymanager.cpp  Definition of QmConfig class.*/QmAutoPtr<QmRecoveryManager> QmRecoveryManager::s_pInstance;/*!  \class QmRecoveryManager qmrecoverymanager.h  \brief Provides functionality for dealing with recovery.  This class can be used to create ~/.apollo/recovery immediately  upon application startup.  The file contains the PID of the Apollo  process.  If Apollo is shutdown properly, that file will be removed.  If, however, Apollo crashes, the file will remain in the directory.  When Apollo starts, it will look for that file, and if so, go into  recovery mode.  Recovery mode provides the user with options on which  files to load or exclude.  This is done because either of these files  may have been corrupted and may cause more problem.*//*!*/QmRecoveryManager::QmRecoveryManager()	: m_LastPid(0){	for(int i = 0; i < QmConfig::ConfigFilesEnd; i++)	{		m_Load[i] = true;	}}/*!*/QmRecoveryManager::~QmRecoveryManager(){}/*!  \return The only instance of the QmRecoveryManager class. Uses QmAutoPtr for storing the object  so it is automaticly destroyed when quitting.*/QmRecoveryManager *QmRecoveryManager::instance(){    if ( QmRecoveryManager::s_pInstance.get() == 0 )    {        s_pInstance.reset( new QmRecoveryManager );    }	    return reinterpret_cast<QmRecoveryManager *>(QmRecoveryManager::s_pInstance.get());}/*!  Set whether the file \a f should load (\a e is true) or not (\a e is false).  \sa loadingEnabled(ConfigFile) */voidQmRecoveryManager::setLoadingEnabled(	QmConfig::ConfigFile f,	bool e){	if(f >= QmConfig::ConfigFilesEnd)	{		qWarning("QmRecoveryManager::setLoading(): Unknown file.");		return;	}	m_Load[f] = e;}/*!  \return True if \a f is to be loaded, false otherwise.  \sa setLoadingEnabled(ConfigFile, bool) */boolQmRecoveryManager::loadingEnabled(	QmConfig::ConfigFile f) const{	if(f >= QmConfig::ConfigFilesEnd)	{		qWarning("QmRecoveryManager::loadingEnabled(): Unknown file.");		return false;	}	return m_Load[f];}/*!  \return True if the recovery file exists, false otherwise.*/boolQmRecoveryManager::recoveryFileExists() const{	return QFile::exists(QmConfig::instance()->configPath() + "recovery");}/*!  \return True if the disable recovery file exists, false otherwise.*/boolQmRecoveryManager::disableRecoveryFileExists() const{	return QFile::exists(QmConfig::instance()->configPath() + "disable-recovery-manager");}/*!  Removes the recovery file.  \sa createRecoveryFile() */voidQmRecoveryManager::removeRecoveryFile() const{	QFile::remove(QmConfig::instance()->configPath() + "recovery");}/*!  Creates the recovery file.  \sa removeRecoveryFile() */voidQmRecoveryManager::createRecoveryFile() const{	QFile f(QmConfig::instance()->configPath() + "recovery");	if ( f.open(IO_WriteOnly) )	{        QTextStream t( &f );        // use a text stream		t << "# This file is safe to delete.  Below is the process ID of Apollo last time it ran.\n";		t << getpid() << "\n";        f.close();    }}/*!  Reads the information in the recovery file. */voidQmRecoveryManager::readRecoveryFile(){	m_LastPid = 0;	QFile f(QmConfig::instance()->configPath() + "recovery");	if ( f.open(IO_ReadOnly) )	{        QTextStream t( &f );        // use a text stream		t.readLine();				// read comment line		m_LastPid = t.readLine().toInt();        f.close();    }}/*!  \return The last saved process ID, or zero if none. */intQmRecoveryManager::lastProcessId() const{	return m_LastPid;}/*! */QmRecoveryManager::RecoveryModeQmRecoveryManager::start(){	if( ! recoveryFileExists() || disableRecoveryFileExists())	{		createRecoveryFile();		return Normal;	}	bool enable_recovery = true;	readRecoveryFile();	int pid = lastProcessId();	if(pid > 0)	{		int rc = kill(pid, 0);		if(rc == -1 && errno == ESRCH)		{			// There is no process with that pid.			enable_recovery = true;		}		else		{			// There is a process with that pid.  It may not be apollo...			int rc = QMessageBox::information(				0, QObject::tr("Apollo - Recovery?"),				QObject::tr(					"Apollo detected that one of the following is possible:<br>"					"<ul>"					"<li>Apollo did not shut down correctly last time it was ran.</li>"					"<li>Apollo is already running (process ID %1).</li>"					"</ul>"					"Neither of these cases are necessarily true and you are given "					"three different options on how to proceed:<br>"					"<ul>"					"<li>If this is a false warning, click 'Start'.</li>"					"<li>If Apollo did not shut down correctly last time, click 'Recovery'.</li>"					"<li>If Apollo is already running, click 'Exit'.</li>"					"</ul>").arg(pid),				QObject::tr("&Start"),				QObject::tr("&Recovery"),				QObject::tr("&Exit"));			if(rc == 0) // Start			{				// Remove old recovery file and create a new one for this session.				removeRecoveryFile();				createRecoveryFile();				enable_recovery = false;			}			else if(rc == 1) // Recovery				enable_recovery = true;			else if(rc == 2) // Exit				return Exit;		}	}	if(enable_recovery)	{		QmRecoveryDialog *dlg = new QmRecoveryDialog;		int rc = dlg->exec();		delete dlg;		if(rc == QmRecoveryDialog::Rejected)			return Exit;		else			return Recovery;	}	return Normal;}/*! */voidQmRecoveryManager::stop(){	// We are about to quit successfully.  Remove the recovery file.	removeRecoveryFile();}

⌨️ 快捷键说明

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