1. Wei Cheng Pan
  2. krapture

Commits

Wei Cheng Pan  committed 294cd4b

Use core module.

  • Participants
  • Parent commits 54a92f4
  • Branches develop

Comments (0)

Files changed (8)

File Krapture/server/src/Sikuli/SikuliClient.cpp

View file
 #include <QtGui/QCursor>
 
 #include "Exception/IOError.hpp"
-#include "Utility/Settings.hpp"
+#include "xTitan/Utility/Setting.hpp"
 
 
 namespace {
 
-	// make complete sikuli bundle path from settings
-	QString getBundlePath( const QString & name ) {
-		QDir tcd( xtitan::Settings::instance().get( "test_cases_path" ).toString() );
-		return tcd.filePath( name ) + ".sikuli";
-	}
+// make complete sikuli bundle path from settings
+QString getBundlePath( const QString & name ) {
+	QDir tcd( xtitan::Setting::instance().get( "test_cases_path" ).toString() );
+	return tcd.filePath( name ) + ".sikuli";
+}
 
 }
 
 	this->client->waitForStarted();
 	// wait window manager animation finished
 	QEventLoop wait;
-	QTimer::singleShot( Settings::instance().get( "test_case_interval" ).toInt(), &wait, SLOT( quit() ) );
+	QTimer::singleShot( Setting::instance().get( "test_case_interval" ).toInt(), &wait, SLOT( quit() ) );
 	wait.exec();
 
 	this->doSuccess = std::bind( &SikuliClient::Private::readBundle, this );
 
 	// TODO command line args support
 	// TODO working directory support
-	QString path( Settings::instance().get( "testing_program_path" ).toString() );
+	QString path( Setting::instance().get( "testing_program_path" ).toString() );
 	QFileInfo info( path );
 	if( !info.exists() ) {
 		throw IOError( QObject::tr( "The program to be testing is not found. (%1)" ).arg( path ) );
 	this->p_->clientPath = path;
 	this->p_->clientWD = info.path();
 
-	path = Settings::instance().get( "sikuliserver_path" ).toString();
+	path = Setting::instance().get( "sikuliserver_path" ).toString();
 	info = path;
 	if( !info.exists() ) {
 		throw IOError( QObject::tr( "The SikuliServer `%1\' is invalid." ).arg( path ) );

File Krapture/server/src/TestCase/TestCaseManager.cpp

View file
 #include <QtSql/QSqlError>
 #include <QtSql/QSqlQuery>
 
-#include "Utility/Settings.hpp"
+#include "xTitan/Utility/Setting.hpp"
 #include "Exception/InternalError.hpp"
 #include "Exception/SqlError.hpp"
 #include "TestCase/TestCase.hpp"
 
 using xtitan::TestCase;
 using xtitan::TestCaseManager;
-using xtitan::Settings;
+using xtitan::Setting;
 using xtitan::IOError;
 using xtitan::SqlError;
 using xtitan::InternalError;
 		this->close();
 	}
 
-	QDir tcDir( Settings::instance().get( "test_cases_path" ).toString() );
+	QDir tcDir( Setting::instance().get( "test_cases_path" ).toString() );
 	if( !tcDir.exists() ) {
 		throw IOError( QObject::tr( "%1 does not exists" ).arg( tcDir.absolutePath() ) );
 	}
 		this->close();
 	}
 
-	QDir tcDir( Settings::instance().get( "test_cases_path" ).toString() );
+	QDir tcDir( Setting::instance().get( "test_cases_path" ).toString() );
 	QString dbPath( tcDir.filePath( "database.sqlite" ) );
 	if( !QFile::exists( dbPath ) ) {
 		throw IOError( QObject::tr( "%1 does not exists" ).arg( dbPath ) );
 		throw SqlError( QObject::tr( "%1 does not exist in database" ).arg( name ) );
 	}
 
-	QDir tcDir( Settings::instance().get( "test_cases_path" ).toString() );
+	QDir tcDir( Setting::instance().get( "test_cases_path" ).toString() );
 	if( !tcDir.cd( name + ".sikuli" ) ) {
 		throw IOError( QObject::tr( "%1.sikuli does not exist" ).arg( name ) );
 	}
 }
 
 void TestCaseManager::save( std::shared_ptr< TestCase > testcase ) {
-	QDir tcDir( Settings::instance().get( "test_cases_path" ).toString() );
+	QDir tcDir( Setting::instance().get( "test_cases_path" ).toString() );
 	if( !tcDir.exists() ) {
 		// if not exists, create it
 		if( !tcDir.mkpath( "." ) ) {

File Krapture/server/src/Utility/Settings.cpp

-/*
-Copyright (c) 2011 Wei Cheng Pan <legnaleurc@gmail.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-#include "Settings_p.hpp"
-
-#include <QtCore/QCoreApplication>
-#include <QtCore/QDir>
-#include <QtCore/QReadLocker>
-#include <QtCore/QSettings>
-#include <QtCore/QTextCodec>
-#include <QtCore/QWriteLocker>
-#include <QtGui/QFont>
-
-#include "Exception/InternalError.hpp"
-
-
-using xtitan::Settings;
-using xtitan::InternalError;
-
-
-std::shared_ptr< Settings > Settings::Private::self;
-
-void Settings::Private::destroy( Settings * self ) {
-	delete self;
-}
-
-Settings::Private::Private(): QObject(), path(), table(), lock() {
-	QDir appDir( QCoreApplication::instance()->applicationDirPath() );
-	this->path = appDir.filePath( "krapture.ini" );
-	QSettings s( this->path, QSettings::IniFormat );
-	s.setIniCodec( QTextCodec::codecForName( "UTF-8" ) );
-
-	this->table.insert( "capture_waiting", s.value( "capture_waiting", 2000 ) );
-	this->table.insert( "font", s.value( "font", QFont( "Lucida Console", 12 ) ) );
-	this->table.insert( "testing_program_path", s.value( "testing_program_path", QString() ) );
-	this->table.insert( "sikuliserver_path", s.value( "sikuliserver_path", appDir.filePath( "SikuliServer.jar" ) ) );
-	this->table.insert( "test_case_interval", s.value( "test_case_interval", 1500 ) );
-	this->table.insert( "test_cases_path", s.value( "test_cases_path", appDir.filePath( "TestCases" ) ) );
-
-	this->connect( QCoreApplication::instance(), SIGNAL( aboutToQuit() ), SLOT( save() ) );
-}
-
-/**
- * @brief Save settings from cache table
- * @note This slot is necessary because the destructing role of Singleton is complicate.
- */
-void Settings::Private::save() {
-	QSettings s( this->path, QSettings::IniFormat );
-	s.setIniCodec( QTextCodec::codecForName( "UTF-8" ) );
-
-	for( QVariantMap::const_iterator it = this->table.begin(); it != this->table.end(); ++it ) {
-		switch( it.value().type() ) {
-		case QVariant::Font:
-			s.setValue( it.key(), it.value().toString() );
-			break;
-		default:
-			s.setValue( it.key(), it.value() );
-		}
-	}
-}
-
-void Settings::initialize() {
-	if( Settings::Private::self ) {
-		return;
-	}
-	Settings::Private::self.reset( new Settings, Settings::Private::destroy );
-}
-
-/**
- * @brief Get global instance
- * @warning This function IS NOT thread-safe
- */
-Settings & Settings::instance() {
-	if( !Settings::Private::self ) {
-		throw InternalError( "Settings has not initialized yet" );
-	}
-	return *Settings::Private::self;
-}
-
-Settings::Settings(): p_( new Private ) {
-}
-
-Settings::~Settings() {
-}
-
-QVariant Settings::get( const QString & key ) const {
-	QReadLocker locker( &this->p_->lock );
-
-	QVariantMap::const_iterator it = this->p_->table.find( key );
-	if( it == this->p_->table.end() ) {
-		return QVariant();
-	}
-	return it.value();
-}
-
-void Settings::set( const QString & key, const QVariant & value ) {
-	QWriteLocker locker( &this->p_->lock );
-
-	if( key.isEmpty() || !value.isValid() ) {
-		return;
-	}
-
-	QVariantMap::iterator it = this->p_->table.find( key );
-	if( it == this->p_->table.end() ) {
-		this->p_->table.insert( key, value );
-	} else {
-		it.value() = value;
-	}
-
-	QSettings s( this->p_->path, QSettings::IniFormat );
-	s.setIniCodec( QTextCodec::codecForName( "UTF-8" ) );
-	s.setValue( key, value );
-}

File Krapture/server/src/Utility/Settings.hpp

-/*
-Copyright (c) 2011 Wei Cheng Pan <legnaleurc@gmail.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-#ifndef KRAPTURE_SETTINGS_HPP
-#define KRAPTURE_SETTINGS_HPP
-
-#include <QtCore/QVariant>
-
-#include <memory>
-
-namespace xtitan {
-
-	class Settings {
-	public:
-		static void initialize();
-		static Settings & instance();
-
-		QVariant get( const QString & key ) const;
-		void set( const QString & key, const QVariant & value );
-
-	private:
-		Settings();
-		~Settings();
-		Settings( const Settings & );
-		Settings & operator =( const Settings & );
-
-		class Private;
-		friend class Private;
-		std::unique_ptr< Private > p_;
-	};
-
-}
-
-#endif

File Krapture/server/src/Utility/Settings_p.hpp

-/*
-Copyright (c) 2011 Wei Cheng Pan <legnaleurc@gmail.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-#ifndef KRAPTURE_SETTINGSPRIVATE_HPP
-#define KRAPTURE_SETTINGSPRIVATE_HPP
-
-#include "settings.hpp"
-
-#include <QtCore/QReadWriteLock>
-
-namespace xtitan {
-
-	class Settings::Private : public QObject {
-		Q_OBJECT
-
-	public slots:
-		void save();
-
-	public:
-		static std::shared_ptr< Settings > self;
-		static void destroy( Settings * self );
-
-		Private();
-
-		QString path;
-		QVariantMap table;
-		QReadWriteLock lock;
-	};
-
-}
-
-#endif

File Krapture/server/src/Utility/main.cpp

View file
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 #include "widget/mainwindow.hpp"
-#include "settings.hpp"
-#include "testcase/testcasemanager.hpp"
+#include "xTitan/Utility/Setting.hpp"
+#include "TestCase/TestCaseManager.hpp"
 #include "krapture/config.h"
 
 #include <QtGui/QApplication>
 	QTextCodec::setCodecForCStrings( QTextCodec::codecForName( "UTF-8" ) );
 	QTextCodec::setCodecForTr( QTextCodec::codecForName( "UTF-8" ) );
 
-	xtitan::Settings::initialize();
+	xtitan::Setting::initialize();
 	xtitan::TestCaseManager::initialize();
 
 	xtitan::MainWindow window;

File Krapture/server/src/Widget/MainWindow.cpp

View file
 #include <QtGui/QMessageBox>
 
 #include "Exception/IOError.hpp"
-#include "Utility/Settings.hpp"
+#include "xTitan/Utility/Setting.hpp"
 #include "TestCase/TestCaseManager.hpp"
 
 
 
 
 using xtitan::MainWindow;
-using xtitan::Settings;
+using xtitan::Setting;
 using xtitan::BasicError;
 using xtitan::IOError;
 
 	this->lockTestCaseUI( true );
 
 	this->buttonTimer->setSingleShot( true );
-	this->buttonTimer->setInterval( Settings::instance().get( "capture_waiting" ).toInt() );
+	this->buttonTimer->setInterval( Setting::instance().get( "capture_waiting" ).toInt() );
 
 	this->onConfigure();
 	this->updateTitle();
 void MainWindow::Private::onRecreateTestCaseDatabase() {
 	QString title( QObject::tr( "Database alert" ) );
 	QString content( QObject::tr( "This action will replace database file in %1, all data will be lost and can not reverse, are you sure?" ) );
-	content = content.arg( Settings::instance().get( "test_cases_path" ).toString() );
+	content = content.arg( Setting::instance().get( "test_cases_path" ).toString() );
 	if( QMessageBox::Yes != QMessageBox::warning( this->host, title, content, QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) ) {
 		return;
 	}
 
 void MainWindow::Private::onConfigure() {
 	QTextDocument * document = this->ui.textEdit->document();
-	document->setDefaultFont( Settings::instance().get( "font" ).value< QFont >() );
+	document->setDefaultFont( Setting::instance().get( "font" ).value< QFont >() );
 }
 
 void MainWindow::Private::onButtonTimeout() {

File Krapture/server/src/Widget/PreferenceDialog.cpp

View file
 #include <QtGui/QFileDialog>
 #include <QtGui/QFontDialog>
 
-#include "Utility/Settings.hpp"
+#include "xTitan/Utility/Setting.hpp"
 
 
 using xtitan::PreferenceDialog;
 }
 
 void PreferenceDialog::Private::load() {
-	this->ui.captureWaiting->setValue( Settings::instance().get( "capture_waiting" ).toInt() );
-	this->font = Settings::instance().get( "font" ).value< QFont >();
+	QDir appDir = QCoreApplication::instance()->applicationDirPath();
+
+	this->ui.captureWaiting->setValue( Setting::instance().get( "capture_waiting", 2000 ).toInt() );
+	this->font = Setting::instance().get( "font", QFont( "Lucida Console", 12 ) ).value< QFont >();
 	this->ui.font->setText( this->font.toString() );
-	this->ui.sikuliserverPath->setText( Settings::instance().get( "sikuliserver_path" ).toString() );
-	this->ui.testCasesPath->setText( Settings::instance().get( "test_cases_path" ).toString() );
-	this->ui.testingPath->setText( Settings::instance().get( "testing_program_path" ).toString() );
-	this->ui.testCaseInterval->setValue( Settings::instance().get( "test_case_interval" ).toInt() );
+	this->ui.sikuliserverPath->setText( Setting::instance().get( "sikuliserver_path", appDir.filePath( "SikuliServer.jar" ) ).toString() );
+	this->ui.testCasesPath->setText( Setting::instance().get( "test_cases_path", appDir.filePath( "TestCases" ) ).toString() );
+	this->ui.testingPath->setText( Setting::instance().get( "testing_program_path", QString() ).toString() );
+	this->ui.testCaseInterval->setValue( Setting::instance().get( "test_case_interval", 1500 ).toInt() );
 }
 
 void PreferenceDialog::Private::save() {
-	Settings::instance().set( "capture_waiting", this->ui.captureWaiting->value() );
-	Settings::instance().set( "font", this->font );
-	Settings::instance().set( "sikuliserver_path", this->ui.sikuliserverPath->text() );
-	Settings::instance().set( "test_cases_path", this->ui.testCasesPath->text() );
-	Settings::instance().set( "testing_program_path", this->ui.testingPath->text() );
-	Settings::instance().set( "test_case_interval", this->ui.testCaseInterval->value() );
+	Setting::instance().set( "capture_waiting", this->ui.captureWaiting->value() );
+	Setting::instance().set( "font", this->font );
+	Setting::instance().set( "sikuliserver_path", this->ui.sikuliserverPath->text() );
+	Setting::instance().set( "test_cases_path", this->ui.testCasesPath->text() );
+	Setting::instance().set( "testing_program_path", this->ui.testingPath->text() );
+	Setting::instance().set( "test_case_interval", this->ui.testCaseInterval->value() );
 }
 
 PreferenceDialog::PreferenceDialog( QWidget * parent ):