From d017bd37253ae35b29d82e3277b9adcbb4517dd0 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 16 Jul 2022 15:18:45 +0900 Subject: Convert files to unix format. Convert C++ header names to C header names. Signed-off-by: Michele Calgaro --- src/AboutDialog.cpp | 10 +- src/AboutDialog.h | 2 +- src/AboutDialogGraphicsView.cpp | 10 +- src/AboutDialogGraphicsView.h | 2 +- src/FindDialog.ui | 242 +++---- src/IndentHandler.cpp | 52 +- src/IndentHandler.h | 2 +- src/MainWindow.cpp | 40 +- src/MainWindow.h | 2 +- src/SettingsPaths.cpp | 550 ++++++++-------- src/SettingsPaths.h | 100 +-- src/TemplateBatchScript.cpp | 2 +- src/TemplateBatchScript.h | 62 +- src/UiGuiErrorMessage.cpp | 2 +- src/UiGuiErrorMessage.h | 86 +-- src/UiGuiHighlighter.cpp | 8 +- src/UiGuiHighlighter.h | 8 +- src/UiGuiIndentServer.cpp | 8 +- src/UiGuiIndentServer.h | 110 ++-- src/UiGuiIniFileParser.cpp | 8 +- src/UiGuiIniFileParser.h | 104 +-- src/UiGuiSettings.cpp | 1376 +++++++++++++++++++-------------------- src/UiGuiSettings.h | 166 ++--- src/UiGuiSettingsDialog.h | 2 +- src/UiGuiSystemInfo.cpp | 454 ++++++------- src/UiGuiSystemInfo.h | 70 +- src/UiGuiVersion.cpp | 122 ++-- src/UiGuiVersion.h | 78 +-- src/UpdateCheckDialog.cpp | 20 +- src/UpdateCheckDialog.h | 146 ++--- src/debugging/TSLogger.cpp | 502 +++++++------- src/debugging/TSLogger.h | 4 +- src/main.cpp | 6 +- 33 files changed, 2178 insertions(+), 2178 deletions(-) (limited to 'src') diff --git a/src/AboutDialog.cpp b/src/AboutDialog.cpp index aa4953a..13957ed 100755 --- a/src/AboutDialog.cpp +++ b/src/AboutDialog.cpp @@ -22,11 +22,11 @@ #include "UiGuiVersion.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /*! \class AboutDialog diff --git a/src/AboutDialog.h b/src/AboutDialog.h index f713d71..adbdf13 100755 --- a/src/AboutDialog.h +++ b/src/AboutDialog.h @@ -20,7 +20,7 @@ #ifndef ABOUTDIALOG_H #define ABOUTDIALOG_H -#include +#include namespace Ui { class AboutDialog; diff --git a/src/AboutDialogGraphicsView.cpp b/src/AboutDialogGraphicsView.cpp index d97cc70..52cb6e1 100755 --- a/src/AboutDialogGraphicsView.cpp +++ b/src/AboutDialogGraphicsView.cpp @@ -21,11 +21,11 @@ #include "AboutDialog.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /*! \class AboutDialogGraphicsView diff --git a/src/AboutDialogGraphicsView.h b/src/AboutDialogGraphicsView.h index ba22c0e..c673149 100755 --- a/src/AboutDialogGraphicsView.h +++ b/src/AboutDialogGraphicsView.h @@ -19,7 +19,7 @@ #ifndef ABOUTDIALOGGRAPHICSVIEW_H #define ABOUTDIALOGGRAPHICSVIEW_H -#include +#include class AboutDialog; diff --git a/src/FindDialog.ui b/src/FindDialog.ui index 943f5a5..f22f574 100755 --- a/src/FindDialog.ui +++ b/src/FindDialog.ui @@ -1,121 +1,121 @@ - - - FindDialog - - - - 0 - 0 - 347 - 227 - - - - Find - - - - - - - 0 - 0 - - - - Find what: - - - - - - - true - - - - - - - - 0 - 0 - - - - Find options - - - - - - Match case - - - - - - - Match whole word - - - - - - - Search forward - - - true - - - - - - - Use Regular Expressions - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - QLayout::SetMaximumSize - - - - - Find Next - - - - - - - Close - - - - - - - - - - + + + FindDialog + + + + 0 + 0 + 347 + 227 + + + + Find + + + + + + + 0 + 0 + + + + Find what: + + + + + + + true + + + + + + + + 0 + 0 + + + + Find options + + + + + + Match case + + + + + + + Match whole word + + + + + + + Search forward + + + true + + + + + + + Use Regular Expressions + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QLayout::SetMaximumSize + + + + + Find Next + + + + + + + Close + + + + + + + + + + diff --git a/src/IndentHandler.cpp b/src/IndentHandler.cpp index a1109c4..2446fa3 100755 --- a/src/IndentHandler.cpp +++ b/src/IndentHandler.cpp @@ -25,32 +25,32 @@ #include "UiGuiIniFileParser.h" #include "SettingsPaths.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef Q_OS_WIN32 #include diff --git a/src/IndentHandler.h b/src/IndentHandler.h index 3ccb553..3f20d82 100755 --- a/src/IndentHandler.h +++ b/src/IndentHandler.h @@ -20,7 +20,7 @@ #ifndef INDENTHANDLER_H #define INDENTHANDLER_H -#include +#include class UiGuiErrorMessage; class UiGuiIniFileParser; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f7b6185..3c12f81 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -33,26 +33,26 @@ #include "IndentHandler.h" #include "UpdateCheckDialog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/MainWindow.h b/src/MainWindow.h index 1205a46..4de1450 100755 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -20,7 +20,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include #include "UiGuiSettings.h" diff --git a/src/SettingsPaths.cpp b/src/SettingsPaths.cpp index f556491..27f9fca 100755 --- a/src/SettingsPaths.cpp +++ b/src/SettingsPaths.cpp @@ -1,275 +1,275 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "SettingsPaths.h" - -#include -#include -#include -#include -#include -#include - -#include - -//! \defgroup grp_Settings All concerning applications settings. - -/*! - \class SettingsPaths - \ingroup grp_Settings - \brief SettingsPaths is a pure static functions class from which info about the - paths needed for settings can be retrieved. -*/ - -bool SettingsPaths::_alreadyInitialized = false; -QString SettingsPaths::_applicationBinaryPath = ""; -QString SettingsPaths::_settingsPath = ""; -QString SettingsPaths::_globalFilesPath = ""; -QString SettingsPaths::_indenterPath = ""; -QString SettingsPaths::_tempPath = ""; -bool SettingsPaths::_portableMode = false; - - -/*! - \brief Initializes all available information about the paths. - - Mainly during this init it is detected whether to start in portable mode or not. This is - done by testing whether the directory "config" is in the same directory as this - applications executable file. - In portable mode all data is ONLY written to subdirectories of the applications executable file. - Means also that the directory "indenters" has to be there. - In not portable mode (multiuser mode) only users home directory is used for writing config data. - */ -void SettingsPaths::init() { - _alreadyInitialized = true; - - qDebug() << __LINE__ << " " << __FUNCTION__ << ": Initializing application paths."; - - // Get the applications binary path, with respect to MacOSXs use of the .app folder. - _applicationBinaryPath = QCoreApplication::applicationDirPath(); - // Remove any trailing slashes - while ( _applicationBinaryPath.right(1) == "/" ) { - _applicationBinaryPath.chop(1); - } - -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - _applicationBinaryPath += "/plugins/uigui"; -#endif - -#ifdef Q_OS_MAC - // Because on Mac universal binaries are used, the binary path is not equal - // to the applications (.app) path. So get the .apps path here. - int indexOfDotApp = _applicationBinaryPath.indexOf(".app"); - if ( indexOfDotApp != -1 ) { - // Cut off after the dot of ".app". - _applicationBinaryPath = _applicationBinaryPath.left( indexOfDotApp-1 ); - // Cut off after the first slash that was in front of ".app" (normally this is the word "UniversalIndentGUI") - _applicationBinaryPath = _applicationBinaryPath.left( _applicationBinaryPath.lastIndexOf("/") ); - } -#endif - - // If the "config" directory is a subdir of the applications binary path, use this one (portable mode) - _settingsPath = _applicationBinaryPath + "/config"; - if ( QFile::exists( _settingsPath ) ) { - _portableMode = true; - QDir dirCreator; - _globalFilesPath = _applicationBinaryPath; - _indenterPath = _applicationBinaryPath + "/indenters"; - dirCreator.mkpath( _settingsPath ); - _tempPath = _applicationBinaryPath + "/temp"; - //TODO: If the portable drive has write protection, use local temp path and clean it up on exit. - dirCreator.mkpath( _tempPath ); - } - // ... otherwise use the system specific global application data path. - else { - _portableMode = false; - QDir dirCreator; -#ifdef Q_OS_WIN - // Get the local users application settings directory. - // Remove any trailing slashes. - _settingsPath = QDir::fromNativeSeparators( qgetenv("APPDATA") ); - while ( _settingsPath.right(1) == "/" ) { - _settingsPath.chop(1); - } - _settingsPath = _settingsPath + "/UniversalIndentGUI"; - - // On windows systems the directories "indenters", "translations" are subdirs of the _applicationBinaryPath. - _globalFilesPath = _applicationBinaryPath; -#else - // Remove any trailing slashes. - _settingsPath = QDir::homePath(); - while ( _settingsPath.right(1) == "/" ) { - _settingsPath.chop(1); - } - _settingsPath = _settingsPath + "/.universalindentgui"; - _globalFilesPath = "/usr/share/universalindentgui"; -#endif - dirCreator.mkpath( _settingsPath ); - // If a highlighter config file does not exist in the users home config dir - // copy the default config file over there. - if ( !QFile::exists(_settingsPath+"/UiGuiSyntaxHighlightConfig.ini") ) { - QFile::copy( _globalFilesPath+"/config/UiGuiSyntaxHighlightConfig.ini", _settingsPath+"/UiGuiSyntaxHighlightConfig.ini" ); - } - _indenterPath = _globalFilesPath + "/indenters"; - - // On different systems it may be that "QDir::tempPath()" ends with a "/" or not. So check this. - // Remove any trailing slashes. - _tempPath = QDir::tempPath(); - while ( _tempPath.right(1) == "/" ) { - _tempPath.chop(1); - } - _tempPath = _tempPath + "/UniversalIndentGUI"; - -#if defined(Q_OS_WIN32) - dirCreator.mkpath( _tempPath ); -#else - // On Unix based systems create a random temporary directory for security - // reasons. Otherwise an evil human being could create a symbolic link - // to an important existing file which gets overwritten when UiGUI writes - // into this normally temporary but linked file. - char *pathTemplate = new char[_tempPath.length()+8]; - QByteArray pathTemplateQBA = QString(_tempPath + "-XXXXXX").toAscii(); - delete [] pathTemplate; - pathTemplate = pathTemplateQBA.data(); - pathTemplate = mkdtemp( pathTemplate ); - _tempPath = pathTemplate; -#endif - } - - qDebug() << __LINE__ << " " << __FUNCTION__ << ": Paths are:" \ - "
  • _applicationBinaryPath=" << _applicationBinaryPath \ - << "
  • _settingsPath=" << _settingsPath \ - << "
  • _globalFilesPath=" << _globalFilesPath \ - << "
  • _indenterPath=" << _indenterPath \ - << "
  • _tempPath=" << _tempPath \ - << "
  • Running in portable mode=" << _portableMode << "
"; -} - - -/*! - \brief Returns the path of the applications executable. - */ -const QString SettingsPaths::getApplicationBinaryPath() { - if ( !_alreadyInitialized ) { - SettingsPaths::init(); - } - return _applicationBinaryPath; -} - - -/*! - \brief Returns the path where all settings are being/should be written to. - */ -const QString SettingsPaths::getSettingsPath() { - if ( !_alreadyInitialized ) { - SettingsPaths::init(); - } - return _settingsPath; -} - - -/*! - \brief Returns the path where the files concerning all users reside. For example translations. - */ -const QString SettingsPaths::getGlobalFilesPath() { - if ( !_alreadyInitialized ) { - SettingsPaths::init(); - } - return _globalFilesPath; -} - - -/*! - \brief Returns the path where the indenter executables reside. - */ -const QString SettingsPaths::getIndenterPath() { - if ( !_alreadyInitialized ) { - SettingsPaths::init(); - } - return _indenterPath; -} - - -/*! - \brief Returns the path where the where all temporary data should be written to. - */ -const QString SettingsPaths::getTempPath() { - if ( !_alreadyInitialized ) { - SettingsPaths::init(); - } - return _tempPath; -} - - -/*! - \brief Returns true if portable mode shall be used. - */ -bool SettingsPaths::getPortableMode() { - if ( !_alreadyInitialized ) { - SettingsPaths::init(); - } - return _portableMode; -} - - -/*! - \brief Completely deletes the created temporary directory with all of its content. - */ -void SettingsPaths::cleanAndRemoveTempDir() { - QDirIterator dirIterator(_tempPath, QDirIterator::Subdirectories); - QStack directoryStack; - bool noErrorsOccurred = true; - - while ( dirIterator.hasNext() ) { - QString currentDirOrFile = dirIterator.next(); - // If this dummy call isn't done here, calling "dirIterator.fileInfo().isDir()" later somehow fails. - dirIterator.fileInfo(); - - if ( !currentDirOrFile.isEmpty() && dirIterator.fileName() != "." && dirIterator.fileName() != ".." ) { - // There is a path on the stack but the current path doesn't start with that path. - // So we changed into another parent directory and the one on the stack can be deleted - // since it must be empty. - if ( !directoryStack.isEmpty() && !currentDirOrFile.startsWith(directoryStack.top()) ) { - QString dirToBeRemoved = directoryStack.pop(); - bool couldRemoveDir = QDir(dirToBeRemoved).rmdir(dirToBeRemoved); - noErrorsOccurred &= couldRemoveDir; - if ( couldRemoveDir == false ) - qWarning() << __LINE__ << " " << __FUNCTION__ << "Could not remove the directory: " << dirToBeRemoved; - //qDebug() << "Removing Dir " << directoryStack.pop(); - } - - // If the iterator currently points to a directory push it onto the stack. - if ( dirIterator.fileInfo().isDir() ) { - directoryStack.push( currentDirOrFile ); - //qDebug() << "Pushing onto Stack " << currentDirOrFile; - } - // otherwise it must be a file, so delete it. - else { - bool couldRemoveFile = QFile::remove( currentDirOrFile ); - noErrorsOccurred &= couldRemoveFile; - if ( couldRemoveFile == false ) - qWarning() << __LINE__ << " " << __FUNCTION__ << "Could not remove the file: " << currentDirOrFile; - //qDebug() << "Removing File " << currentDirOrFile; - } - } - } - noErrorsOccurred &= QDir(_tempPath).rmdir(_tempPath); - if ( noErrorsOccurred == false ) - qWarning() << __LINE__ << " " << __FUNCTION__ << "While cleaning up the temp dir an error occurred."; -} +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "SettingsPaths.h" + +#include +#include +#include +#include +#include +#include + +#include + +//! \defgroup grp_Settings All concerning applications settings. + +/*! + \class SettingsPaths + \ingroup grp_Settings + \brief SettingsPaths is a pure static functions class from which info about the + paths needed for settings can be retrieved. +*/ + +bool SettingsPaths::_alreadyInitialized = false; +QString SettingsPaths::_applicationBinaryPath = ""; +QString SettingsPaths::_settingsPath = ""; +QString SettingsPaths::_globalFilesPath = ""; +QString SettingsPaths::_indenterPath = ""; +QString SettingsPaths::_tempPath = ""; +bool SettingsPaths::_portableMode = false; + + +/*! + \brief Initializes all available information about the paths. + + Mainly during this init it is detected whether to start in portable mode or not. This is + done by testing whether the directory "config" is in the same directory as this + applications executable file. + In portable mode all data is ONLY written to subdirectories of the applications executable file. + Means also that the directory "indenters" has to be there. + In not portable mode (multiuser mode) only users home directory is used for writing config data. + */ +void SettingsPaths::init() { + _alreadyInitialized = true; + + qDebug() << __LINE__ << " " << __FUNCTION__ << ": Initializing application paths."; + + // Get the applications binary path, with respect to MacOSXs use of the .app folder. + _applicationBinaryPath = QCoreApplication::applicationDirPath(); + // Remove any trailing slashes + while ( _applicationBinaryPath.right(1) == "/" ) { + _applicationBinaryPath.chop(1); + } + +#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS + _applicationBinaryPath += "/plugins/uigui"; +#endif + +#ifdef Q_OS_MAC + // Because on Mac universal binaries are used, the binary path is not equal + // to the applications (.app) path. So get the .apps path here. + int indexOfDotApp = _applicationBinaryPath.indexOf(".app"); + if ( indexOfDotApp != -1 ) { + // Cut off after the dot of ".app". + _applicationBinaryPath = _applicationBinaryPath.left( indexOfDotApp-1 ); + // Cut off after the first slash that was in front of ".app" (normally this is the word "UniversalIndentGUI") + _applicationBinaryPath = _applicationBinaryPath.left( _applicationBinaryPath.lastIndexOf("/") ); + } +#endif + + // If the "config" directory is a subdir of the applications binary path, use this one (portable mode) + _settingsPath = _applicationBinaryPath + "/config"; + if ( QFile::exists( _settingsPath ) ) { + _portableMode = true; + QDir dirCreator; + _globalFilesPath = _applicationBinaryPath; + _indenterPath = _applicationBinaryPath + "/indenters"; + dirCreator.mkpath( _settingsPath ); + _tempPath = _applicationBinaryPath + "/temp"; + //TODO: If the portable drive has write protection, use local temp path and clean it up on exit. + dirCreator.mkpath( _tempPath ); + } + // ... otherwise use the system specific global application data path. + else { + _portableMode = false; + QDir dirCreator; +#ifdef Q_OS_WIN + // Get the local users application settings directory. + // Remove any trailing slashes. + _settingsPath = QDir::fromNativeSeparators( qgetenv("APPDATA") ); + while ( _settingsPath.right(1) == "/" ) { + _settingsPath.chop(1); + } + _settingsPath = _settingsPath + "/UniversalIndentGUI"; + + // On windows systems the directories "indenters", "translations" are subdirs of the _applicationBinaryPath. + _globalFilesPath = _applicationBinaryPath; +#else + // Remove any trailing slashes. + _settingsPath = QDir::homePath(); + while ( _settingsPath.right(1) == "/" ) { + _settingsPath.chop(1); + } + _settingsPath = _settingsPath + "/.universalindentgui"; + _globalFilesPath = "/usr/share/universalindentgui"; +#endif + dirCreator.mkpath( _settingsPath ); + // If a highlighter config file does not exist in the users home config dir + // copy the default config file over there. + if ( !QFile::exists(_settingsPath+"/UiGuiSyntaxHighlightConfig.ini") ) { + QFile::copy( _globalFilesPath+"/config/UiGuiSyntaxHighlightConfig.ini", _settingsPath+"/UiGuiSyntaxHighlightConfig.ini" ); + } + _indenterPath = _globalFilesPath + "/indenters"; + + // On different systems it may be that "QDir::tempPath()" ends with a "/" or not. So check this. + // Remove any trailing slashes. + _tempPath = QDir::tempPath(); + while ( _tempPath.right(1) == "/" ) { + _tempPath.chop(1); + } + _tempPath = _tempPath + "/UniversalIndentGUI"; + +#if defined(Q_OS_WIN32) + dirCreator.mkpath( _tempPath ); +#else + // On Unix based systems create a random temporary directory for security + // reasons. Otherwise an evil human being could create a symbolic link + // to an important existing file which gets overwritten when UiGUI writes + // into this normally temporary but linked file. + char *pathTemplate = new char[_tempPath.length()+8]; + QByteArray pathTemplateQBA = QString(_tempPath + "-XXXXXX").toAscii(); + delete [] pathTemplate; + pathTemplate = pathTemplateQBA.data(); + pathTemplate = mkdtemp( pathTemplate ); + _tempPath = pathTemplate; +#endif + } + + qDebug() << __LINE__ << " " << __FUNCTION__ << ": Paths are:" \ + "
  • _applicationBinaryPath=" << _applicationBinaryPath \ + << "
  • _settingsPath=" << _settingsPath \ + << "
  • _globalFilesPath=" << _globalFilesPath \ + << "
  • _indenterPath=" << _indenterPath \ + << "
  • _tempPath=" << _tempPath \ + << "
  • Running in portable mode=" << _portableMode << "
"; +} + + +/*! + \brief Returns the path of the applications executable. + */ +const QString SettingsPaths::getApplicationBinaryPath() { + if ( !_alreadyInitialized ) { + SettingsPaths::init(); + } + return _applicationBinaryPath; +} + + +/*! + \brief Returns the path where all settings are being/should be written to. + */ +const QString SettingsPaths::getSettingsPath() { + if ( !_alreadyInitialized ) { + SettingsPaths::init(); + } + return _settingsPath; +} + + +/*! + \brief Returns the path where the files concerning all users reside. For example translations. + */ +const QString SettingsPaths::getGlobalFilesPath() { + if ( !_alreadyInitialized ) { + SettingsPaths::init(); + } + return _globalFilesPath; +} + + +/*! + \brief Returns the path where the indenter executables reside. + */ +const QString SettingsPaths::getIndenterPath() { + if ( !_alreadyInitialized ) { + SettingsPaths::init(); + } + return _indenterPath; +} + + +/*! + \brief Returns the path where the where all temporary data should be written to. + */ +const QString SettingsPaths::getTempPath() { + if ( !_alreadyInitialized ) { + SettingsPaths::init(); + } + return _tempPath; +} + + +/*! + \brief Returns true if portable mode shall be used. + */ +bool SettingsPaths::getPortableMode() { + if ( !_alreadyInitialized ) { + SettingsPaths::init(); + } + return _portableMode; +} + + +/*! + \brief Completely deletes the created temporary directory with all of its content. + */ +void SettingsPaths::cleanAndRemoveTempDir() { + QDirIterator dirIterator(_tempPath, QDirIterator::Subdirectories); + QStack directoryStack; + bool noErrorsOccurred = true; + + while ( dirIterator.hasNext() ) { + QString currentDirOrFile = dirIterator.next(); + // If this dummy call isn't done here, calling "dirIterator.fileInfo().isDir()" later somehow fails. + dirIterator.fileInfo(); + + if ( !currentDirOrFile.isEmpty() && dirIterator.fileName() != "." && dirIterator.fileName() != ".." ) { + // There is a path on the stack but the current path doesn't start with that path. + // So we changed into another parent directory and the one on the stack can be deleted + // since it must be empty. + if ( !directoryStack.isEmpty() && !currentDirOrFile.startsWith(directoryStack.top()) ) { + QString dirToBeRemoved = directoryStack.pop(); + bool couldRemoveDir = QDir(dirToBeRemoved).rmdir(dirToBeRemoved); + noErrorsOccurred &= couldRemoveDir; + if ( couldRemoveDir == false ) + qWarning() << __LINE__ << " " << __FUNCTION__ << "Could not remove the directory: " << dirToBeRemoved; + //qDebug() << "Removing Dir " << directoryStack.pop(); + } + + // If the iterator currently points to a directory push it onto the stack. + if ( dirIterator.fileInfo().isDir() ) { + directoryStack.push( currentDirOrFile ); + //qDebug() << "Pushing onto Stack " << currentDirOrFile; + } + // otherwise it must be a file, so delete it. + else { + bool couldRemoveFile = QFile::remove( currentDirOrFile ); + noErrorsOccurred &= couldRemoveFile; + if ( couldRemoveFile == false ) + qWarning() << __LINE__ << " " << __FUNCTION__ << "Could not remove the file: " << currentDirOrFile; + //qDebug() << "Removing File " << currentDirOrFile; + } + } + } + noErrorsOccurred &= QDir(_tempPath).rmdir(_tempPath); + if ( noErrorsOccurred == false ) + qWarning() << __LINE__ << " " << __FUNCTION__ << "While cleaning up the temp dir an error occurred."; +} diff --git a/src/SettingsPaths.h b/src/SettingsPaths.h index 71f17e3..3442216 100755 --- a/src/SettingsPaths.h +++ b/src/SettingsPaths.h @@ -1,50 +1,50 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef SETTINGSPATHS_H -#define SETTINGSPATHS_H - -class QString; - - -class SettingsPaths -{ -public: - static void init(); - static const QString getApplicationBinaryPath(); - static const QString getSettingsPath(); - static const QString getGlobalFilesPath(); - static const QString getIndenterPath(); - static const QString getTempPath(); - static bool getPortableMode(); - static void cleanAndRemoveTempDir(); - -private: - SettingsPaths(); - - static bool _alreadyInitialized; - static QString _applicationBinaryPath; - static QString _settingsPath; - static QString _globalFilesPath; - static QString _indenterPath; - static QString _tempPath; - static bool _portableMode; -}; - -#endif // SETTINGSPATHS_H +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef SETTINGSPATHS_H +#define SETTINGSPATHS_H + +class QString; + + +class SettingsPaths +{ +public: + static void init(); + static const QString getApplicationBinaryPath(); + static const QString getSettingsPath(); + static const QString getGlobalFilesPath(); + static const QString getIndenterPath(); + static const QString getTempPath(); + static bool getPortableMode(); + static void cleanAndRemoveTempDir(); + +private: + SettingsPaths(); + + static bool _alreadyInitialized; + static QString _applicationBinaryPath; + static QString _settingsPath; + static QString _globalFilesPath; + static QString _indenterPath; + static QString _tempPath; + static bool _portableMode; +}; + +#endif // SETTINGSPATHS_H diff --git a/src/TemplateBatchScript.cpp b/src/TemplateBatchScript.cpp index 00c96ce..e8a91e8 100755 --- a/src/TemplateBatchScript.cpp +++ b/src/TemplateBatchScript.cpp @@ -20,7 +20,7 @@ #include "TemplateBatchScript.h" // Need to include QObject here so that platform specific defines like Q_OS_WIN32 are set. -#include +#include /*! \brief The only and static function of this class returns a batch or shell script diff --git a/src/TemplateBatchScript.h b/src/TemplateBatchScript.h index ff14ade..4a71a11 100755 --- a/src/TemplateBatchScript.h +++ b/src/TemplateBatchScript.h @@ -1,31 +1,31 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef TEMPLATEBATCHSCRIPT_H -#define TEMPLATEBATCHSCRIPT_H - -class TemplateBatchScript -{ -private: - TemplateBatchScript(); -public: - static const char* getTemplateBatchScript(); -}; - -#endif // TEMPLATEBATCHSCRIPT_H +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef TEMPLATEBATCHSCRIPT_H +#define TEMPLATEBATCHSCRIPT_H + +class TemplateBatchScript +{ +private: + TemplateBatchScript(); +public: + static const char* getTemplateBatchScript(); +}; + +#endif // TEMPLATEBATCHSCRIPT_H diff --git a/src/UiGuiErrorMessage.cpp b/src/UiGuiErrorMessage.cpp index 424a709..63aed21 100755 --- a/src/UiGuiErrorMessage.cpp +++ b/src/UiGuiErrorMessage.cpp @@ -19,7 +19,7 @@ #include "UiGuiErrorMessage.h" -#include +#include /*! \class UiGuiErrorMessage diff --git a/src/UiGuiErrorMessage.h b/src/UiGuiErrorMessage.h index f520795..ce5b405 100755 --- a/src/UiGuiErrorMessage.h +++ b/src/UiGuiErrorMessage.h @@ -1,43 +1,43 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef UIGUIERRORMESSAGE_H -#define UIGUIERRORMESSAGE_H - -#include - -class QCheckBox; - - -class UiGuiErrorMessage : public QErrorMessage -{ - Q_OBJECT - -public: - UiGuiErrorMessage(QWidget *parent = 0); - ~UiGuiErrorMessage(void); - void showMessage( const QString &message ); - void showMessage( const QString &title, const QString &message ); - -private: - QCheckBox *_showAgainCheckBox; - QStringList _errorMessageList; -}; - -#endif // UIGUIERRORMESSAGE_H +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef UIGUIERRORMESSAGE_H +#define UIGUIERRORMESSAGE_H + +#include + +class QCheckBox; + + +class UiGuiErrorMessage : public QErrorMessage +{ + Q_OBJECT + +public: + UiGuiErrorMessage(QWidget *parent = 0); + ~UiGuiErrorMessage(void); + void showMessage( const QString &message ); + void showMessage( const QString &title, const QString &message ); + +private: + QCheckBox *_showAgainCheckBox; + QStringList _errorMessageList; +}; + +#endif // UIGUIERRORMESSAGE_H diff --git a/src/UiGuiHighlighter.cpp b/src/UiGuiHighlighter.cpp index ac74909..e35a8ec 100755 --- a/src/UiGuiHighlighter.cpp +++ b/src/UiGuiHighlighter.cpp @@ -21,10 +21,10 @@ #include "SettingsPaths.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/src/UiGuiHighlighter.h b/src/UiGuiHighlighter.h index d0d60d4..4ac0f35 100755 --- a/src/UiGuiHighlighter.h +++ b/src/UiGuiHighlighter.h @@ -20,10 +20,10 @@ #ifndef UIGUIHIGHLIGHTER_H #define UIGUIHIGHLIGHTER_H -#include -#include -#include -#include +#include +#include +#include +#include class QAction; class QSettings; diff --git a/src/UiGuiIndentServer.cpp b/src/UiGuiIndentServer.cpp index 0dfc93f..8a93094 100755 --- a/src/UiGuiIndentServer.cpp +++ b/src/UiGuiIndentServer.cpp @@ -19,10 +19,10 @@ #include "UiGuiIndentServer.h" -#include -#include -#include -#include +#include +#include +#include +#include //! \defgroup grp_Server All concerning the server component. diff --git a/src/UiGuiIndentServer.h b/src/UiGuiIndentServer.h index 837693a..79f4606 100755 --- a/src/UiGuiIndentServer.h +++ b/src/UiGuiIndentServer.h @@ -1,55 +1,55 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef UIGUIINDENTSERVER_H -#define UIGUIINDENTSERVER_H - -#include - -class QTcpServer; -class QTcpSocket; - - -class UiGuiIndentServer : public QObject -{ - Q_OBJECT - -public: - UiGuiIndentServer(void); - ~UiGuiIndentServer(void); - -public slots: - void startServer(); - void stopServer(); - -private slots: - void handleNewConnection(); - void handleReceivedData(); - void sendMessage(const QString &message); - void checkIfReadyForHandleRequest(); - -private: - QTcpServer *_tcpServer; - QByteArray _dataToSend; - bool _readyForHandleRequest; - QTcpSocket *_currentClientConnection; - quint32 _blockSize; -}; - -#endif // UIGUIINDENTSERVER_H +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef UIGUIINDENTSERVER_H +#define UIGUIINDENTSERVER_H + +#include + +class QTcpServer; +class QTcpSocket; + + +class UiGuiIndentServer : public QObject +{ + Q_OBJECT + +public: + UiGuiIndentServer(void); + ~UiGuiIndentServer(void); + +public slots: + void startServer(); + void stopServer(); + +private slots: + void handleNewConnection(); + void handleReceivedData(); + void sendMessage(const QString &message); + void checkIfReadyForHandleRequest(); + +private: + QTcpServer *_tcpServer; + QByteArray _dataToSend; + bool _readyForHandleRequest; + QTcpSocket *_currentClientConnection; + quint32 _blockSize; +}; + +#endif // UIGUIINDENTSERVER_H diff --git a/src/UiGuiIniFileParser.cpp b/src/UiGuiIniFileParser.cpp index 84542e0..9e1a023 100755 --- a/src/UiGuiIniFileParser.cpp +++ b/src/UiGuiIniFileParser.cpp @@ -19,10 +19,10 @@ #include "UiGuiIniFileParser.h" -#include -#include -#include -#include +#include +#include +#include +#include //! \defgroup grp_Settings All concerning applications settings. diff --git a/src/UiGuiIniFileParser.h b/src/UiGuiIniFileParser.h index cbbc3c9..84c19a7 100755 --- a/src/UiGuiIniFileParser.h +++ b/src/UiGuiIniFileParser.h @@ -1,52 +1,52 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef UIGUIINIFILEPARSER_H -#define UIGUIINIFILEPARSER_H - -#include -#include - -#include - -class QStringList; -class QVariant; - - -class UiGuiIniFileParser -{ -public: - UiGuiIniFileParser(void); - UiGuiIniFileParser(const QString &iniFileName); - ~UiGuiIniFileParser(void); - QVariant value(const QString &keyName, const QString &defaultValue = ""); - QStringList childGroups(); - -protected: - void init(); - -private: - void parseIniFile(); - - QString _iniFileName; - std::vector _sections; - QMap _keyValueMap; -}; - -#endif // UIGUIINIFILEPARSER_H +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef UIGUIINIFILEPARSER_H +#define UIGUIINIFILEPARSER_H + +#include +#include + +#include + +class QStringList; +class QVariant; + + +class UiGuiIniFileParser +{ +public: + UiGuiIniFileParser(void); + UiGuiIniFileParser(const QString &iniFileName); + ~UiGuiIniFileParser(void); + QVariant value(const QString &keyName, const QString &defaultValue = ""); + QStringList childGroups(); + +protected: + void init(); + +private: + void parseIniFile(); + + QString _iniFileName; + std::vector _sections; + QMap _keyValueMap; +}; + +#endif // UIGUIINIFILEPARSER_H diff --git a/src/UiGuiSettings.cpp b/src/UiGuiSettings.cpp index f997ec3..5d8349b 100755 --- a/src/UiGuiSettings.cpp +++ b/src/UiGuiSettings.cpp @@ -1,688 +1,688 @@ -/*************************************************************************** -* Copyright (C) 2006-2012 by Thomas Schweitzer * -* thomas-schweitzer(at)arcor.de * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License version 2.0 as * -* published by the Free Software Foundation. * -* * -* 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 in the file LICENSE.GPL; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ - -#include "UiGuiSettings.h" - -#include "SettingsPaths.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//! \defgroup grp_Settings All concerning the settings. - -/*! - \class UiGuiSettings - \ingroup grp_Settings - \brief Handles the settings of the program. Reads them on startup and saves them on exit. - Is a singleton class and can only be accessed via getInstance(). -*/ - -// Inits the single class instance pointer. -QWeakPointer UiGuiSettings::_instance; - - -/*! - \brief The constructor for the settings. -*/ -UiGuiSettings::UiGuiSettings() : QObject() { - // Create the main application settings object from the UniversalIndentGUI.ini file. - _qsettings = new QSettings(SettingsPaths::getSettingsPath() + "/UniversalIndentGUI.ini", QSettings::IniFormat, this); - - _indenterDirctoryStr = SettingsPaths::getGlobalFilesPath() + "/indenters"; - readAvailableTranslations(); - initSettings(); -} - - -/*! - \brief Returns the instance of the settings class. If no instance exists, ONE will be created. - */ -QSharedPointer UiGuiSettings::getInstance() { - QSharedPointer sharedInstance = _instance.toStrongRef(); - if ( sharedInstance.isNull() ) { - // Create the settings object, which loads all UiGui settings from a file. - sharedInstance = QSharedPointer(new UiGuiSettings()); - _instance = sharedInstance.toWeakRef(); - } - - return sharedInstance; -} - - -/*! - \brief The destructor saves the settings to a file. - */ -UiGuiSettings::~UiGuiSettings() { - // Convert the language setting from an integer index to a string. - int index = _qsettings->value("UniversalIndentGUI/language", 0).toInt(); - if ( index < 0 || index >= _availableTranslations.size() ) - index = 0; - - _qsettings->setValue( "UniversalIndentGUI/language", _availableTranslations.at(index) ); -} - - -/*! - \brief Scans the translations directory for available translation files and - stores them in the QList \a _availableTranslations. - */ -void UiGuiSettings::readAvailableTranslations() { - QString languageShort; - QStringList languageFileList; - - // English is the default language. A translation file does not exist but to have a menu entry, added here. - languageFileList << "universalindent_en.qm"; - - // Find all translation files in the "translations" directory. - QDir translationDirectory = QDir( SettingsPaths::getGlobalFilesPath() + "/translations" ); - languageFileList << translationDirectory.entryList( QStringList("universalindent_*.qm") ); - - // Loop for each found translation file - foreach ( languageShort, languageFileList ) { - // Remove the leading string "universalindent_" from the filename. - languageShort.remove(0,16); - // Remove trailing file extension ".qm". - languageShort.chop(3); - - _availableTranslations.append(languageShort); - } -} - - -/*! - \brief Returns a list of the mnemonics of the available translations. - */ -QStringList UiGuiSettings::getAvailableTranslations() { - return _availableTranslations; -} - - -/*! - \brief Returns the value of the by \a settingsName defined setting as QVariant. - - If the named setting does not exist, 0 is being returned. -*/ -QVariant UiGuiSettings::getValueByName(QString settingName) { - return _qsettings->value("UniversalIndentGUI/" + settingName); -} - - -/*! - \brief Loads the settings for the main application. - - Settings are for example last selected indenter, last loaded source code file and so on. -*/ -bool UiGuiSettings::initSettings() -{ - // Read the version string saved in the settings file. - _qsettings->setValue( "UniversalIndentGUI/version", _qsettings->value("UniversalIndentGUI/version", "") ); - - // Read windows last size and position from the settings file. - _qsettings->setValue( "UniversalIndentGUI/maximized", _qsettings->value("UniversalIndentGUI/maximized", false) ); - _qsettings->setValue( "UniversalIndentGUI/position", _qsettings->value("UniversalIndentGUI/position", QPoint(50, 50)) ); - _qsettings->setValue( "UniversalIndentGUI/size", _qsettings->value("UniversalIndentGUI/size", QSize(800, 600)) ); - - // Read last selected encoding for the opened source code file. - _qsettings->setValue( "UniversalIndentGUI/encoding", _qsettings->value("UniversalIndentGUI/encoding", "UTF-8") ); - - // Read maximum length of list for recently opened files. - _qsettings->setValue( "UniversalIndentGUI/recentlyOpenedListSize", _qsettings->value("UniversalIndentGUI/recentlyOpenedListSize", 5) ); - - // Read if last opened source code file should be loaded on startup. - _qsettings->setValue( "UniversalIndentGUI/loadLastSourceCodeFileOnStartup", _qsettings->value("UniversalIndentGUI/loadLastSourceCodeFileOnStartup", true) ); - - // Read last opened source code file from the settings file. - _qsettings->setValue( "UniversalIndentGUI/lastSourceCodeFile", _qsettings->value("UniversalIndentGUI/lastSourceCodeFile", _indenterDirctoryStr+"/example.cpp") ); - - // Read last selected indenter from the settings file. - int selectedIndenter = _qsettings->value("UniversalIndentGUI/selectedIndenter", 0).toInt(); - if ( selectedIndenter < 0 ) { - selectedIndenter = 0; - } - _qsettings->setValue( "UniversalIndentGUI/selectedIndenter", selectedIndenter ); - - // Read if syntax highlighting is enabled. - _qsettings->setValue( "UniversalIndentGUI/SyntaxHighlightingEnabled", _qsettings->value("UniversalIndentGUI/SyntaxHighlightingEnabled", true) ); - - // Read if white space characters should be displayed. - _qsettings->setValue( "UniversalIndentGUI/whiteSpaceIsVisible", _qsettings->value("UniversalIndentGUI/whiteSpaceIsVisible", false) ); - - // Read if indenter parameter tool tips are enabled. - _qsettings->setValue( "UniversalIndentGUI/indenterParameterTooltipsEnabled", _qsettings->value("UniversalIndentGUI/indenterParameterTooltipsEnabled", true) ); - - // Read the tab width from the settings file. - _qsettings->setValue( "UniversalIndentGUI/tabWidth", _qsettings->value("UniversalIndentGUI/tabWidth", 4) ); - - // Read the last selected language and stores the index it has in the list of available translations. - _qsettings->setValue( "UniversalIndentGUI/language", _availableTranslations.indexOf( _qsettings->value("UniversalIndentGUI/language", "").toString() ) ); - - // Read the update check settings from the settings file. - _qsettings->setValue( "UniversalIndentGUI/CheckForUpdate", _qsettings->value("UniversalIndentGUI/CheckForUpdate", false) ); - _qsettings->setValue( "UniversalIndentGUI/LastUpdateCheck", _qsettings->value("UniversalIndentGUI/LastUpdateCheck", QDate(1900,1,1)) ); - - // Read the main window state. - _qsettings->setValue( "UniversalIndentGUI/MainWindowState", _qsettings->value("UniversalIndentGUI/MainWindowState", QByteArray()) ); - - return true; -} - - -/*! - \brief Register the by \a propertyName defined property of \a obj to be connected to the setting defined by \a settingName. - - The \a propertyName must be one of those that are listed in the Qt "Properties" documentation section of a Qt Object. - All further needed info is retrieved via the \a obj's MetaObject, like the to the property bound signal. - */ -bool UiGuiSettings::registerObjectProperty( QObject *obj, const QString &propertyName, const QString &settingName ) -{ - const QMetaObject *metaObject = obj->metaObject(); - bool connectSuccess = false; - - // Connect to the objects destroyed signal, so that it will be correctly unregistered. - connectSuccess = connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectProperty(QObject*))); - - int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); - if ( connectSuccess && indexOfProp > -1 ) { - QMetaProperty mProp = metaObject->property(indexOfProp); - - // Connect to the property's value changed signal. - if ( mProp.hasNotifySignal() ) { - QMetaMethod signal = mProp.notifySignal(); - //QString teststr = qPrintable(SIGNAL() + QString(signal.signature())); - // The command "SIGNAL() + QString(signal.signature())" assembles the signal methods signature to a valid Qt SIGNAL. - connectSuccess = connect(obj, qPrintable(SIGNAL() + QString(signal.signature())), this, SLOT(handleObjectPropertyChange())); - } - - if ( connectSuccess ) { - _registeredObjectProperties[obj] = QStringList() << propertyName << settingName; - } - else { - //TODO: Write a debug warning to the log. - disconnect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectProperty(QObject*))); - return false; - } - - // If setting already exists, set the objects property to the setting value. - if ( _qsettings->contains("UniversalIndentGUI/" + settingName) ) { - mProp.write(obj, _qsettings->value("UniversalIndentGUI/" + settingName)); - } - // Otherwise add the setting and set it to the value of the objects property. - else { - _qsettings->setValue("UniversalIndentGUI/" + settingName, mProp.read(obj)); - } - } - else { - //TODO: Write a debug warning to the log. - disconnect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectProperty(QObject*))); - return false; - } - - return true; -} - - -/*! - \brief Searches the child QObjects of \a obj for a property name and setting name definition within - their custom properties and registers this property name to that setting name if both were found. - - The custom properties, for which are searched, are "connectedPropertyName" and "connectedSettingName", - where "connectedPropertyName" is the name of a QObject property as it is documented in the QtDocs, and - "connectedSettingName" is the name of a setting here within UiGuiSettings. If the mentioned setting - name doesn't exist, it will be created. - - Returns true, if all found property and setting definitions could be successfully registered. - Returns false, if any of those registrations fails. - */ -bool UiGuiSettings::registerObjectPropertyRecursive(QObject *obj) { - return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::registerObjectProperty); -} - - -/*! - \brief Assigns the by \a settingName defined setting value to the by \a propertyName defined property of \a obj. - - Returns true, if the value could be assigned, otherwise returns false, which is the case if settingName doesn't exist - within the settings or if the mentioned propertyName wasn't found for the \a obj. - */ -bool UiGuiSettings::setObjectPropertyToSettingValue( QObject *obj, const QString &propertyName, const QString &settingName ) -{ - const QMetaObject *metaObject = obj->metaObject(); - - int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); - if ( indexOfProp > -1 ) { - QMetaProperty mProp = metaObject->property(indexOfProp); - - // If setting already exists, set the objects property to the setting value. - if ( _qsettings->contains("UniversalIndentGUI/" + settingName) ) { - mProp.write(obj, _qsettings->value("UniversalIndentGUI/" + settingName)); - } - // The setting didn't exist so return that setting the objects property failed. - else { - //TODO: Write a debug warning to the log. - return false; - } - } - else { - //TODO: Write a debug warning to the log. - return false; - } - - return true; -} - - -/*! - \brief Searches the child QObjects of \a obj for a property name and setting name definition within - their custom properties and sets each property to settings value. - - The custom properties, for which are searched, are "connectedPropertyName" and "connectedSettingName", - where "connectedPropertyName" is the name of a QObject property as it is documented in the QtDocs, and - "connectedSettingName" is the name of a setting here within UiGuiSettings. - - Returns true, if all found property and setting definitions could be successfully registered. - Returns false, if any of those registrations fails. - */ -bool UiGuiSettings::setObjectPropertyToSettingValueRecursive(QObject *obj) { - return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::setObjectPropertyToSettingValue); -} - - -/*! - \brief Assigns the by \a propertyName defined property's value of \a obj to the by \a settingName defined setting. - - If the \a settingName didn't exist yet, it will be created. - - Returns true, if the value could be assigned, otherwise returns false, which is the case if the mentioned - propertyName wasn't found for the \a obj. - */ -bool UiGuiSettings::setSettingToObjectPropertyValue( QObject *obj, const QString &propertyName, const QString &settingName ) -{ - const QMetaObject *metaObject = obj->metaObject(); - - int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); - if ( indexOfProp > -1 ) { - QMetaProperty mProp = metaObject->property(indexOfProp); - - setValueByName(settingName, mProp.read(obj)); - } - else { - //TODO: Write a debug warning to the log. - return false; - } - - return true; -} - - -/*! - \brief Searches the child QObjects of \a obj for a property name and setting name definition within - their custom properties and sets each setting to the property value. - - The custom properties, for which are searched, are "connectedPropertyName" and "connectedSettingName", - where "connectedPropertyName" is the name of a QObject property as it is documented in the QtDocs, and - "connectedSettingName" is the name of a setting here within UiGuiSettings. If the settingName - didn't exist yet, it will be created. - - Returns true, if all found property and setting definitions could be successfully registered. - Returns false, if any of those registrations fails. - */ -bool UiGuiSettings::setSettingToObjectPropertyValueRecursive(QObject *obj) { - return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::setSettingToObjectPropertyValue); -} - - -/*! - \brief Iterates over all \a objs child QObjects and checks whether they have the custom properties - "connectedPropertyName" and "connectedSettingName" set. If both are set, it invokes the \a callBackFunc - with both. - */ -bool UiGuiSettings::checkCustomPropertiesAndCallFunction(QObject *obj, bool (UiGuiSettings::*callBackFunc)(QObject *obj, const QString &propertyName, const QString &settingName)) { - bool success = true; - - // Find all widgets that have PropertyName and SettingName defined in their style sheet. - QList allObjects = obj->findChildren(); - foreach (QObject *object, allObjects) { - QString propertyName = object->property("connectedPropertyName").toString(); - QString settingName = object->property("connectedSettingName").toString(); - - // If property and setting name were found, register that widget with the settings. - if ( !propertyName.isEmpty() && !settingName.isEmpty() ) { - success &= (this->*callBackFunc)( object, propertyName, settingName ); - } - } - - return success; -} - - -/*! - \brief The with a certain property registered \a obj gets unregistered. - */ -void UiGuiSettings::unregisterObjectProperty(QObject *obj) { - if ( _registeredObjectProperties.contains(obj) ) { - const QMetaObject *metaObject = obj->metaObject(); - QString propertyName = _registeredObjectProperties[obj].first(); - QString settingName = _registeredObjectProperties[obj].last(); - - bool connectSuccess = false; - int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); - if ( indexOfProp > -1 ) { - QMetaProperty mProp = metaObject->property(indexOfProp); - - // Disconnect to the property's value changed signal. - if ( mProp.hasNotifySignal() ) { - QMetaMethod signal = mProp.notifySignal(); - // The command "SIGNAL() + QString(signal.signature())" assembles the signal methods signature to a valid Qt SIGNAL. - connectSuccess = disconnect(obj, qPrintable(SIGNAL() + QString(signal.signature())), this, SLOT(handleObjectPropertyChange())); - } - } - _registeredObjectProperties.remove(obj); - } -} - - -/*! - \brief Registers a slot form the \a obj by its \a slotName to be invoked, if the by \a settingName defined - setting changes. - - The registered slot may have no parameters or exactly one. If it accepts one parameter, whenever the setting - \a settingName changes the slot gets tried to be invoked with the settings value as parameter. This only works, - if the slot parameter is of the same type as the setting. - */ -bool UiGuiSettings::registerObjectSlot(QObject *obj, const QString &slotName, const QString &settingName) { - - const QMetaObject *metaObject = obj->metaObject(); - - bool connectSuccess = false; - // Connect to the objects destroyed signal, so that it will be correctly unregistered. - connectSuccess = connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectSlot(QObject*))); - - QString normalizedSlotName = QMetaObject::normalizedSignature( qPrintable(slotName) ); - int indexOfMethod = metaObject->indexOfMethod( qPrintable(normalizedSlotName) ); - if ( connectSuccess && indexOfMethod > -1 ) { - QMetaMethod mMethod = metaObject->method(indexOfMethod); - //QMetaMethod::Access access = mMethod.access(); - //QMetaMethod::MethodType methType = mMethod.methodType(); - - // Since the method can at maximum be invoked with the setting value as argument, - // only methods taking max one argument are allowed. - if ( mMethod.parameterTypes().size() <= 1 ) { - _registeredObjectSlots.insert(obj, QStringList() << normalizedSlotName << settingName); - } - else { - //TODO: Write a debug warning to the log. - disconnect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectSlot(QObject*))); - return false; - } - } - else { - //TODO: Write a debug warning to the log. - disconnect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectSlot(QObject*))); - return false; - } - - return true; -} - - -/*! - \brief If \a obj, \a slotName and \a settingName are given, that certain connection is unregistered. - If only \a obj is given, all to this object registered slot-setting connections are unregistered. - */ -void UiGuiSettings::unregisterObjectSlot(QObject *obj, const QString &slotName, const QString &settingName) { - //const QMetaObject *metaObject = obj->metaObject(); - QString normalizedSlotName = QMetaObject::normalizedSignature( qPrintable(slotName) ); - QMutableMapIterator it(_registeredObjectSlots); - while (it.hasNext()) { - it.next(); - if (it.key() == obj && slotName.isEmpty() && settingName.isEmpty()) - it.remove(); - else if (it.key() == obj && it.value().first() == slotName && it.value().last() == settingName) - it.remove(); - } -} - - -/*! - \brief This private slot gets invoked whenever a registered objects property changes - and distributes the new value to all other to the same settingName registered objects. - */ -void UiGuiSettings::handleObjectPropertyChange() { - QObject *obj = QObject::sender(); - QString className = obj->metaObject()->className(); - const QMetaObject *metaObject = obj->metaObject(); - QString propertyName = _registeredObjectProperties[obj].first(); - QString settingName = _registeredObjectProperties[obj].last(); - - int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); - if ( indexOfProp > -1 ) { - QMetaProperty mProp = metaObject->property(indexOfProp); - setValueByName(settingName, mProp.read(obj)); - } -} - - -/*! - \brief Sets the setting defined by \a settingName to \a value. - - When setting a changed value, all to this settingName registered objects get - the changed value set too. - If the \a settingName didn't exist yet, it will be created. - */ -void UiGuiSettings::setValueByName(const QString &settingName, const QVariant &value) { - // Do the updating only, if the setting was really changed. - if ( _qsettings->value("UniversalIndentGUI/" + settingName) != value ) { - _qsettings->setValue("UniversalIndentGUI/" + settingName, value); - - // Set the new value for all registered object properties for settingName. - for ( QMap::ConstIterator it = _registeredObjectProperties.begin(); it != _registeredObjectProperties.end(); ++it ) { - if ( it.value().last() == settingName ) { - QObject *obj = it.key(); - const QMetaObject *metaObject = obj->metaObject(); - QString propertyName = it.value().first(); - - int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); - if ( indexOfProp > -1 ) { - QMetaProperty mProp = metaObject->property(indexOfProp); - mProp.write(obj, value); - } - } - } - - // Invoke all registered object methods for settingName. - for ( QMap::ConstIterator it = _registeredObjectSlots.begin(); it != _registeredObjectSlots.end(); ++it ) { - if ( it.value().last() == settingName ) { - QObject *obj = it.key(); - const QMetaObject *metaObject = obj->metaObject(); - QString slotName = it.value().first(); - - int indexOfMethod = metaObject->indexOfMethod( qPrintable(slotName) ); - if ( indexOfMethod > -1 ) { - QMetaMethod mMethod = metaObject->method(indexOfMethod); - //QMetaMethod::Access access = mMethod.access(); - //QMetaMethod::MethodType methType = mMethod.methodType(); - - bool success = false; - - // Handle registered slots taking one parameter. - if ( mMethod.parameterTypes().size() == 1 ) { - if ( mMethod.parameterTypes().first() == value.typeName() ) { - success = invokeMethodWithValue(obj, mMethod, value); - } - } - // Handle registered slots taking zero parameters. - else { - success = mMethod.invoke( obj, Qt::DirectConnection ); - } - - if ( success == false ) { - // TODO: Write a warning to the log if no success. - } - } - } - } - } -} - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if QT_VERSION >= 0x040600 -#include -#include -#endif - -bool UiGuiSettings::invokeMethodWithValue( QObject *obj, QMetaMethod mMethod, QVariant value ) -{ - switch (value.type()) { - case QVariant::BitArray : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QBitArray, value.toBitArray()) ); - case QVariant::Bitmap : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QBitmap, value.value()) ); - case QVariant::Bool : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(bool, value.toBool()) ); - case QVariant::Brush : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QBrush, value.value()) ); - case QVariant::ByteArray : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QByteArray, value.toByteArray()) ); - case QVariant::Char : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QChar, value.toChar()) ); - case QVariant::Color : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QColor, value.value()) ); - case QVariant::Cursor : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QCursor, value.value()) ); - case QVariant::Date : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QDate, value.toDate()) ); - case QVariant::DateTime : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QDateTime, value.toDateTime()) ); - case QVariant::Double : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(double, value.toDouble()) ); - case QVariant::Font : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QFont, value.value()) ); - case QVariant::Hash : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVariantHash, value.toHash()) ); - case QVariant::Icon : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QIcon, value.value()) ); - case QVariant::Image : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QImage, value.value()) ); - case QVariant::Int : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(int, value.toInt()) ); - case QVariant::KeySequence : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QKeySequence, value.value()) ); - case QVariant::Line : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QLine, value.toLine()) ); - case QVariant::LineF : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QLineF, value.toLineF()) ); - case QVariant::List : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVariantList, value.toList()) ); - case QVariant::Locale : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QLocale, value.toLocale()) ); - case QVariant::LongLong : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(qlonglong, value.toLongLong()) ); - case QVariant::Map : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVariantMap, value.toMap()) ); - case QVariant::Matrix : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QMatrix, value.value()) ); - case QVariant::Transform : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QTransform, value.value()) ); -#if QT_VERSION >= 0x040600 - case QVariant::Matrix4x4 : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QMatrix4x4, value.value()) ); -#endif - case QVariant::Palette : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPalette, value.value()) ); - case QVariant::Pen : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPen, value.value()) ); - case QVariant::Pixmap : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPixmap, value.value()) ); - case QVariant::Point : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPoint, value.toPoint()) ); - // case QVariant::PointArray : - // return Q_ARG(QPointArray, value.value()) ); - case QVariant::PointF : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPointF, value.toPointF()) ); - case QVariant::Polygon : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPolygon, value.value()) ); -#if QT_VERSION >= 0x040600 - case QVariant::Quaternion : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QQuaternion, value.value()) ); -#endif - case QVariant::Rect : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QRect, value.toRect()) ); - case QVariant::RectF : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QRectF, value.toRectF()) ); - case QVariant::RegExp : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QRegExp, value.toRegExp()) ); - case QVariant::Region : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QRegion, value.value()) ); - case QVariant::Size : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QSize, value.toSize()) ); - case QVariant::SizeF : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QSizeF, value.toSizeF()) ); - case QVariant::SizePolicy : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QSizePolicy, value.value()) ); - case QVariant::String : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QString, value.toString()) ); - case QVariant::StringList : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QStringList, value.toStringList()) ); - case QVariant::TextFormat : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QTextFormat, value.value()) ); - case QVariant::TextLength : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QTextLength, value.value()) ); - case QVariant::Time : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QTime, value.toTime()) ); - case QVariant::UInt : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(uint, value.toUInt()) ); - case QVariant::ULongLong : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(qulonglong, value.toULongLong()) ); - case QVariant::Url : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QUrl, value.toUrl()) ); -#if QT_VERSION >= 0x040600 - case QVariant::Vector2D : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVector2D, value.value()) ); - case QVariant::Vector3D : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVector3D, value.value()) ); - case QVariant::Vector4D : - return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVector4D, value.value()) ); -#endif - default: - return false; - } -} +/*************************************************************************** +* Copyright (C) 2006-2012 by Thomas Schweitzer * +* thomas-schweitzer(at)arcor.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License version 2.0 as * +* published by the Free Software Foundation. * +* * +* 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 in the file LICENSE.GPL; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#include "UiGuiSettings.h" + +#include "SettingsPaths.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//! \defgroup grp_Settings All concerning the settings. + +/*! + \class UiGuiSettings + \ingroup grp_Settings + \brief Handles the settings of the program. Reads them on startup and saves them on exit. + Is a singleton class and can only be accessed via getInstance(). +*/ + +// Inits the single class instance pointer. +QWeakPointer UiGuiSettings::_instance; + + +/*! + \brief The constructor for the settings. +*/ +UiGuiSettings::UiGuiSettings() : QObject() { + // Create the main application settings object from the UniversalIndentGUI.ini file. + _qsettings = new QSettings(SettingsPaths::getSettingsPath() + "/UniversalIndentGUI.ini", QSettings::IniFormat, this); + + _indenterDirctoryStr = SettingsPaths::getGlobalFilesPath() + "/indenters"; + readAvailableTranslations(); + initSettings(); +} + + +/*! + \brief Returns the instance of the settings class. If no instance exists, ONE will be created. + */ +QSharedPointer UiGuiSettings::getInstance() { + QSharedPointer sharedInstance = _instance.toStrongRef(); + if ( sharedInstance.isNull() ) { + // Create the settings object, which loads all UiGui settings from a file. + sharedInstance = QSharedPointer(new UiGuiSettings()); + _instance = sharedInstance.toWeakRef(); + } + + return sharedInstance; +} + + +/*! + \brief The destructor saves the settings to a file. + */ +UiGuiSettings::~UiGuiSettings() { + // Convert the language setting from an integer index to a string. + int index = _qsettings->value("UniversalIndentGUI/language", 0).toInt(); + if ( index < 0 || index >= _availableTranslations.size() ) + index = 0; + + _qsettings->setValue( "UniversalIndentGUI/language", _availableTranslations.at(index) ); +} + + +/*! + \brief Scans the translations directory for available translation files and + stores them in the QList \a _availableTranslations. + */ +void UiGuiSettings::readAvailableTranslations() { + QString languageShort; + QStringList languageFileList; + + // English is the default language. A translation file does not exist but to have a menu entry, added here. + languageFileList << "universalindent_en.qm"; + + // Find all translation files in the "translations" directory. + QDir translationDirectory = QDir( SettingsPaths::getGlobalFilesPath() + "/translations" ); + languageFileList << translationDirectory.entryList( QStringList("universalindent_*.qm") ); + + // Loop for each found translation file + foreach ( languageShort, languageFileList ) { + // Remove the leading string "universalindent_" from the filename. + languageShort.remove(0,16); + // Remove trailing file extension ".qm". + languageShort.chop(3); + + _availableTranslations.append(languageShort); + } +} + + +/*! + \brief Returns a list of the mnemonics of the available translations. + */ +QStringList UiGuiSettings::getAvailableTranslations() { + return _availableTranslations; +} + + +/*! + \brief Returns the value of the by \a settingsName defined setting as QVariant. + + If the named setting does not exist, 0 is being returned. +*/ +QVariant UiGuiSettings::getValueByName(QString settingName) { + return _qsettings->value("UniversalIndentGUI/" + settingName); +} + + +/*! + \brief Loads the settings for the main application. + + Settings are for example last selected indenter, last loaded source code file and so on. +*/ +bool UiGuiSettings::initSettings() +{ + // Read the version string saved in the settings file. + _qsettings->setValue( "UniversalIndentGUI/version", _qsettings->value("UniversalIndentGUI/version", "") ); + + // Read windows last size and position from the settings file. + _qsettings->setValue( "UniversalIndentGUI/maximized", _qsettings->value("UniversalIndentGUI/maximized", false) ); + _qsettings->setValue( "UniversalIndentGUI/position", _qsettings->value("UniversalIndentGUI/position", QPoint(50, 50)) ); + _qsettings->setValue( "UniversalIndentGUI/size", _qsettings->value("UniversalIndentGUI/size", QSize(800, 600)) ); + + // Read last selected encoding for the opened source code file. + _qsettings->setValue( "UniversalIndentGUI/encoding", _qsettings->value("UniversalIndentGUI/encoding", "UTF-8") ); + + // Read maximum length of list for recently opened files. + _qsettings->setValue( "UniversalIndentGUI/recentlyOpenedListSize", _qsettings->value("UniversalIndentGUI/recentlyOpenedListSize", 5) ); + + // Read if last opened source code file should be loaded on startup. + _qsettings->setValue( "UniversalIndentGUI/loadLastSourceCodeFileOnStartup", _qsettings->value("UniversalIndentGUI/loadLastSourceCodeFileOnStartup", true) ); + + // Read last opened source code file from the settings file. + _qsettings->setValue( "UniversalIndentGUI/lastSourceCodeFile", _qsettings->value("UniversalIndentGUI/lastSourceCodeFile", _indenterDirctoryStr+"/example.cpp") ); + + // Read last selected indenter from the settings file. + int selectedIndenter = _qsettings->value("UniversalIndentGUI/selectedIndenter", 0).toInt(); + if ( selectedIndenter < 0 ) { + selectedIndenter = 0; + } + _qsettings->setValue( "UniversalIndentGUI/selectedIndenter", selectedIndenter ); + + // Read if syntax highlighting is enabled. + _qsettings->setValue( "UniversalIndentGUI/SyntaxHighlightingEnabled", _qsettings->value("UniversalIndentGUI/SyntaxHighlightingEnabled", true) ); + + // Read if white space characters should be displayed. + _qsettings->setValue( "UniversalIndentGUI/whiteSpaceIsVisible", _qsettings->value("UniversalIndentGUI/whiteSpaceIsVisible", false) ); + + // Read if indenter parameter tool tips are enabled. + _qsettings->setValue( "UniversalIndentGUI/indenterParameterTooltipsEnabled", _qsettings->value("UniversalIndentGUI/indenterParameterTooltipsEnabled", true) ); + + // Read the tab width from the settings file. + _qsettings->setValue( "UniversalIndentGUI/tabWidth", _qsettings->value("UniversalIndentGUI/tabWidth", 4) ); + + // Read the last selected language and stores the index it has in the list of available translations. + _qsettings->setValue( "UniversalIndentGUI/language", _availableTranslations.indexOf( _qsettings->value("UniversalIndentGUI/language", "").toString() ) ); + + // Read the update check settings from the settings file. + _qsettings->setValue( "UniversalIndentGUI/CheckForUpdate", _qsettings->value("UniversalIndentGUI/CheckForUpdate", false) ); + _qsettings->setValue( "UniversalIndentGUI/LastUpdateCheck", _qsettings->value("UniversalIndentGUI/LastUpdateCheck", QDate(1900,1,1)) ); + + // Read the main window state. + _qsettings->setValue( "UniversalIndentGUI/MainWindowState", _qsettings->value("UniversalIndentGUI/MainWindowState", QByteArray()) ); + + return true; +} + + +/*! + \brief Register the by \a propertyName defined property of \a obj to be connected to the setting defined by \a settingName. + + The \a propertyName must be one of those that are listed in the Qt "Properties" documentation section of a Qt Object. + All further needed info is retrieved via the \a obj's MetaObject, like the to the property bound signal. + */ +bool UiGuiSettings::registerObjectProperty( QObject *obj, const QString &propertyName, const QString &settingName ) +{ + const QMetaObject *metaObject = obj->metaObject(); + bool connectSuccess = false; + + // Connect to the objects destroyed signal, so that it will be correctly unregistered. + connectSuccess = connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectProperty(QObject*))); + + int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); + if ( connectSuccess && indexOfProp > -1 ) { + QMetaProperty mProp = metaObject->property(indexOfProp); + + // Connect to the property's value changed signal. + if ( mProp.hasNotifySignal() ) { + QMetaMethod signal = mProp.notifySignal(); + //QString teststr = qPrintable(SIGNAL() + QString(signal.signature())); + // The command "SIGNAL() + QString(signal.signature())" assembles the signal methods signature to a valid Qt SIGNAL. + connectSuccess = connect(obj, qPrintable(SIGNAL() + QString(signal.signature())), this, SLOT(handleObjectPropertyChange())); + } + + if ( connectSuccess ) { + _registeredObjectProperties[obj] = QStringList() << propertyName << settingName; + } + else { + //TODO: Write a debug warning to the log. + disconnect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectProperty(QObject*))); + return false; + } + + // If setting already exists, set the objects property to the setting value. + if ( _qsettings->contains("UniversalIndentGUI/" + settingName) ) { + mProp.write(obj, _qsettings->value("UniversalIndentGUI/" + settingName)); + } + // Otherwise add the setting and set it to the value of the objects property. + else { + _qsettings->setValue("UniversalIndentGUI/" + settingName, mProp.read(obj)); + } + } + else { + //TODO: Write a debug warning to the log. + disconnect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectProperty(QObject*))); + return false; + } + + return true; +} + + +/*! + \brief Searches the child QObjects of \a obj for a property name and setting name definition within + their custom properties and registers this property name to that setting name if both were found. + + The custom properties, for which are searched, are "connectedPropertyName" and "connectedSettingName", + where "connectedPropertyName" is the name of a QObject property as it is documented in the QtDocs, and + "connectedSettingName" is the name of a setting here within UiGuiSettings. If the mentioned setting + name doesn't exist, it will be created. + + Returns true, if all found property and setting definitions could be successfully registered. + Returns false, if any of those registrations fails. + */ +bool UiGuiSettings::registerObjectPropertyRecursive(QObject *obj) { + return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::registerObjectProperty); +} + + +/*! + \brief Assigns the by \a settingName defined setting value to the by \a propertyName defined property of \a obj. + + Returns true, if the value could be assigned, otherwise returns false, which is the case if settingName doesn't exist + within the settings or if the mentioned propertyName wasn't found for the \a obj. + */ +bool UiGuiSettings::setObjectPropertyToSettingValue( QObject *obj, const QString &propertyName, const QString &settingName ) +{ + const QMetaObject *metaObject = obj->metaObject(); + + int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); + if ( indexOfProp > -1 ) { + QMetaProperty mProp = metaObject->property(indexOfProp); + + // If setting already exists, set the objects property to the setting value. + if ( _qsettings->contains("UniversalIndentGUI/" + settingName) ) { + mProp.write(obj, _qsettings->value("UniversalIndentGUI/" + settingName)); + } + // The setting didn't exist so return that setting the objects property failed. + else { + //TODO: Write a debug warning to the log. + return false; + } + } + else { + //TODO: Write a debug warning to the log. + return false; + } + + return true; +} + + +/*! + \brief Searches the child QObjects of \a obj for a property name and setting name definition within + their custom properties and sets each property to settings value. + + The custom properties, for which are searched, are "connectedPropertyName" and "connectedSettingName", + where "connectedPropertyName" is the name of a QObject property as it is documented in the QtDocs, and + "connectedSettingName" is the name of a setting here within UiGuiSettings. + + Returns true, if all found property and setting definitions could be successfully registered. + Returns false, if any of those registrations fails. + */ +bool UiGuiSettings::setObjectPropertyToSettingValueRecursive(QObject *obj) { + return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::setObjectPropertyToSettingValue); +} + + +/*! + \brief Assigns the by \a propertyName defined property's value of \a obj to the by \a settingName defined setting. + + If the \a settingName didn't exist yet, it will be created. + + Returns true, if the value could be assigned, otherwise returns false, which is the case if the mentioned + propertyName wasn't found for the \a obj. + */ +bool UiGuiSettings::setSettingToObjectPropertyValue( QObject *obj, const QString &propertyName, const QString &settingName ) +{ + const QMetaObject *metaObject = obj->metaObject(); + + int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); + if ( indexOfProp > -1 ) { + QMetaProperty mProp = metaObject->property(indexOfProp); + + setValueByName(settingName, mProp.read(obj)); + } + else { + //TODO: Write a debug warning to the log. + return false; + } + + return true; +} + + +/*! + \brief Searches the child QObjects of \a obj for a property name and setting name definition within + their custom properties and sets each setting to the property value. + + The custom properties, for which are searched, are "connectedPropertyName" and "connectedSettingName", + where "connectedPropertyName" is the name of a QObject property as it is documented in the QtDocs, and + "connectedSettingName" is the name of a setting here within UiGuiSettings. If the settingName + didn't exist yet, it will be created. + + Returns true, if all found property and setting definitions could be successfully registered. + Returns false, if any of those registrations fails. + */ +bool UiGuiSettings::setSettingToObjectPropertyValueRecursive(QObject *obj) { + return checkCustomPropertiesAndCallFunction(obj, &UiGuiSettings::setSettingToObjectPropertyValue); +} + + +/*! + \brief Iterates over all \a objs child QObjects and checks whether they have the custom properties + "connectedPropertyName" and "connectedSettingName" set. If both are set, it invokes the \a callBackFunc + with both. + */ +bool UiGuiSettings::checkCustomPropertiesAndCallFunction(QObject *obj, bool (UiGuiSettings::*callBackFunc)(QObject *obj, const QString &propertyName, const QString &settingName)) { + bool success = true; + + // Find all widgets that have PropertyName and SettingName defined in their style sheet. + QList allObjects = obj->findChildren(); + foreach (QObject *object, allObjects) { + QString propertyName = object->property("connectedPropertyName").toString(); + QString settingName = object->property("connectedSettingName").toString(); + + // If property and setting name were found, register that widget with the settings. + if ( !propertyName.isEmpty() && !settingName.isEmpty() ) { + success &= (this->*callBackFunc)( object, propertyName, settingName ); + } + } + + return success; +} + + +/*! + \brief The with a certain property registered \a obj gets unregistered. + */ +void UiGuiSettings::unregisterObjectProperty(QObject *obj) { + if ( _registeredObjectProperties.contains(obj) ) { + const QMetaObject *metaObject = obj->metaObject(); + QString propertyName = _registeredObjectProperties[obj].first(); + QString settingName = _registeredObjectProperties[obj].last(); + + bool connectSuccess = false; + int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); + if ( indexOfProp > -1 ) { + QMetaProperty mProp = metaObject->property(indexOfProp); + + // Disconnect to the property's value changed signal. + if ( mProp.hasNotifySignal() ) { + QMetaMethod signal = mProp.notifySignal(); + // The command "SIGNAL() + QString(signal.signature())" assembles the signal methods signature to a valid Qt SIGNAL. + connectSuccess = disconnect(obj, qPrintable(SIGNAL() + QString(signal.signature())), this, SLOT(handleObjectPropertyChange())); + } + } + _registeredObjectProperties.remove(obj); + } +} + + +/*! + \brief Registers a slot form the \a obj by its \a slotName to be invoked, if the by \a settingName defined + setting changes. + + The registered slot may have no parameters or exactly one. If it accepts one parameter, whenever the setting + \a settingName changes the slot gets tried to be invoked with the settings value as parameter. This only works, + if the slot parameter is of the same type as the setting. + */ +bool UiGuiSettings::registerObjectSlot(QObject *obj, const QString &slotName, const QString &settingName) { + + const QMetaObject *metaObject = obj->metaObject(); + + bool connectSuccess = false; + // Connect to the objects destroyed signal, so that it will be correctly unregistered. + connectSuccess = connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectSlot(QObject*))); + + QString normalizedSlotName = QMetaObject::normalizedSignature( qPrintable(slotName) ); + int indexOfMethod = metaObject->indexOfMethod( qPrintable(normalizedSlotName) ); + if ( connectSuccess && indexOfMethod > -1 ) { + QMetaMethod mMethod = metaObject->method(indexOfMethod); + //QMetaMethod::Access access = mMethod.access(); + //QMetaMethod::MethodType methType = mMethod.methodType(); + + // Since the method can at maximum be invoked with the setting value as argument, + // only methods taking max one argument are allowed. + if ( mMethod.parameterTypes().size() <= 1 ) { + _registeredObjectSlots.insert(obj, QStringList() << normalizedSlotName << settingName); + } + else { + //TODO: Write a debug warning to the log. + disconnect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectSlot(QObject*))); + return false; + } + } + else { + //TODO: Write a debug warning to the log. + disconnect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterObjectSlot(QObject*))); + return false; + } + + return true; +} + + +/*! + \brief If \a obj, \a slotName and \a settingName are given, that certain connection is unregistered. + If only \a obj is given, all to this object registered slot-setting connections are unregistered. + */ +void UiGuiSettings::unregisterObjectSlot(QObject *obj, const QString &slotName, const QString &settingName) { + //const QMetaObject *metaObject = obj->metaObject(); + QString normalizedSlotName = QMetaObject::normalizedSignature( qPrintable(slotName) ); + QMutableMapIterator it(_registeredObjectSlots); + while (it.hasNext()) { + it.next(); + if (it.key() == obj && slotName.isEmpty() && settingName.isEmpty()) + it.remove(); + else if (it.key() == obj && it.value().first() == slotName && it.value().last() == settingName) + it.remove(); + } +} + + +/*! + \brief This private slot gets invoked whenever a registered objects property changes + and distributes the new value to all other to the same settingName registered objects. + */ +void UiGuiSettings::handleObjectPropertyChange() { + QObject *obj = QObject::sender(); + QString className = obj->metaObject()->className(); + const QMetaObject *metaObject = obj->metaObject(); + QString propertyName = _registeredObjectProperties[obj].first(); + QString settingName = _registeredObjectProperties[obj].last(); + + int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); + if ( indexOfProp > -1 ) { + QMetaProperty mProp = metaObject->property(indexOfProp); + setValueByName(settingName, mProp.read(obj)); + } +} + + +/*! + \brief Sets the setting defined by \a settingName to \a value. + + When setting a changed value, all to this settingName registered objects get + the changed value set too. + If the \a settingName didn't exist yet, it will be created. + */ +void UiGuiSettings::setValueByName(const QString &settingName, const QVariant &value) { + // Do the updating only, if the setting was really changed. + if ( _qsettings->value("UniversalIndentGUI/" + settingName) != value ) { + _qsettings->setValue("UniversalIndentGUI/" + settingName, value); + + // Set the new value for all registered object properties for settingName. + for ( QMap::ConstIterator it = _registeredObjectProperties.begin(); it != _registeredObjectProperties.end(); ++it ) { + if ( it.value().last() == settingName ) { + QObject *obj = it.key(); + const QMetaObject *metaObject = obj->metaObject(); + QString propertyName = it.value().first(); + + int indexOfProp = metaObject->indexOfProperty( qPrintable(propertyName) ); + if ( indexOfProp > -1 ) { + QMetaProperty mProp = metaObject->property(indexOfProp); + mProp.write(obj, value); + } + } + } + + // Invoke all registered object methods for settingName. + for ( QMap::ConstIterator it = _registeredObjectSlots.begin(); it != _registeredObjectSlots.end(); ++it ) { + if ( it.value().last() == settingName ) { + QObject *obj = it.key(); + const QMetaObject *metaObject = obj->metaObject(); + QString slotName = it.value().first(); + + int indexOfMethod = metaObject->indexOfMethod( qPrintable(slotName) ); + if ( indexOfMethod > -1 ) { + QMetaMethod mMethod = metaObject->method(indexOfMethod); + //QMetaMethod::Access access = mMethod.access(); + //QMetaMethod::MethodType methType = mMethod.methodType(); + + bool success = false; + + // Handle registered slots taking one parameter. + if ( mMethod.parameterTypes().size() == 1 ) { + if ( mMethod.parameterTypes().first() == value.typeName() ) { + success = invokeMethodWithValue(obj, mMethod, value); + } + } + // Handle registered slots taking zero parameters. + else { + success = mMethod.invoke( obj, Qt::DirectConnection ); + } + + if ( success == false ) { + // TODO: Write a warning to the log if no success. + } + } + } + } + } +} + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if QT_VERSION >= 0x040600 +#include +#include +#endif + +bool UiGuiSettings::invokeMethodWithValue( QObject *obj, QMetaMethod mMethod, QVariant value ) +{ + switch (value.type()) { + case QVariant::BitArray : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QBitArray, value.toBitArray()) ); + case QVariant::Bitmap : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QBitmap, value.value()) ); + case QVariant::Bool : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(bool, value.toBool()) ); + case QVariant::Brush : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QBrush, value.value()) ); + case QVariant::ByteArray : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QByteArray, value.toByteArray()) ); + case QVariant::Char : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QChar, value.toChar()) ); + case QVariant::Color : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QColor, value.value()) ); + case QVariant::Cursor : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QCursor, value.value()) ); + case QVariant::Date : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QDate, value.toDate()) ); + case QVariant::DateTime : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QDateTime, value.toDateTime()) ); + case QVariant::Double : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(double, value.toDouble()) ); + case QVariant::Font : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QFont, value.value()) ); + case QVariant::Hash : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVariantHash, value.toHash()) ); + case QVariant::Icon : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QIcon, value.value()) ); + case QVariant::Image : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QImage, value.value()) ); + case QVariant::Int : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(int, value.toInt()) ); + case QVariant::KeySequence : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QKeySequence, value.value()) ); + case QVariant::Line : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QLine, value.toLine()) ); + case QVariant::LineF : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QLineF, value.toLineF()) ); + case QVariant::List : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVariantList, value.toList()) ); + case QVariant::Locale : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QLocale, value.toLocale()) ); + case QVariant::LongLong : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(qlonglong, value.toLongLong()) ); + case QVariant::Map : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVariantMap, value.toMap()) ); + case QVariant::Matrix : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QMatrix, value.value()) ); + case QVariant::Transform : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QTransform, value.value()) ); +#if QT_VERSION >= 0x040600 + case QVariant::Matrix4x4 : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QMatrix4x4, value.value()) ); +#endif + case QVariant::Palette : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPalette, value.value()) ); + case QVariant::Pen : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPen, value.value()) ); + case QVariant::Pixmap : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPixmap, value.value()) ); + case QVariant::Point : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPoint, value.toPoint()) ); + // case QVariant::PointArray : + // return Q_ARG(QPointArray, value.value()) ); + case QVariant::PointF : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPointF, value.toPointF()) ); + case QVariant::Polygon : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QPolygon, value.value()) ); +#if QT_VERSION >= 0x040600 + case QVariant::Quaternion : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QQuaternion, value.value()) ); +#endif + case QVariant::Rect : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QRect, value.toRect()) ); + case QVariant::RectF : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QRectF, value.toRectF()) ); + case QVariant::RegExp : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QRegExp, value.toRegExp()) ); + case QVariant::Region : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QRegion, value.value()) ); + case QVariant::Size : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QSize, value.toSize()) ); + case QVariant::SizeF : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QSizeF, value.toSizeF()) ); + case QVariant::SizePolicy : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QSizePolicy, value.value()) ); + case QVariant::String : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QString, value.toString()) ); + case QVariant::StringList : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QStringList, value.toStringList()) ); + case QVariant::TextFormat : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QTextFormat, value.value()) ); + case QVariant::TextLength : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QTextLength, value.value()) ); + case QVariant::Time : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QTime, value.toTime()) ); + case QVariant::UInt : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(uint, value.toUInt()) ); + case QVariant::ULongLong : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(qulonglong, value.toULongLong()) ); + case QVariant::Url : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QUrl, value.toUrl()) ); +#if QT_VERSION >= 0x040600 + case QVariant::Vector2D : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVector2D, value.value()) ); + case QVariant::Vector3D : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVector3D, value.value()) ); + case QVariant::Vector4D : + return mMethod.invoke( obj, Qt::DirectConnection, Q_ARG(QVector4D, value.value()) ); +#endif + default: + return false; + } +} diff --git a/src/UiGuiSettings.h b/src/UiGuiSettings.h index 54f4dca..c818199 100755 --- a/src/UiGuiSettings.h +++ b/src/UiGuiSettings.h @@ -1,83 +1,83 @@ -/*************************************************************************** -* Copyright (C) 2006-2012 by Thomas Schweitzer * -* thomas-schweitzer(at)arcor.de * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License version 2.0 as * -* published by the Free Software Foundation. * -* * -* 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 in the file LICENSE.GPL; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ - -#ifndef UIGUISETTINGS_H -#define UIGUISETTINGS_H - -#include -#include -#include -#include - -class QSettings; - - -class UiGuiSettings : public QObject -{ - Q_OBJECT -private: - UiGuiSettings(); - static QWeakPointer _instance; - -public: - static QSharedPointer getInstance(); - ~UiGuiSettings(); - - bool registerObjectProperty(QObject *obj, const QString &propertyName, const QString &settingName); - bool registerObjectPropertyRecursive(QObject *obj); - bool setObjectPropertyToSettingValue(QObject *obj, const QString &propertyName, const QString &settingName); - bool setObjectPropertyToSettingValueRecursive(QObject *obj); - bool setSettingToObjectPropertyValue(QObject *obj, const QString &propertyName, const QString &settingName); - bool setSettingToObjectPropertyValueRecursive(QObject *obj); - bool registerObjectSlot(QObject *obj, const QString &slotName, const QString &settingName); - QVariant getValueByName(QString settingName); - QStringList getAvailableTranslations(); - -public slots: - void setValueByName(const QString &settingName, const QVariant &value); - void unregisterObjectProperty(QObject *obj); - void unregisterObjectSlot(QObject *obj, const QString &slotName = "", const QString &settingName = ""); - -protected: - bool initSettings(); - bool invokeMethodWithValue(QObject *obj, QMetaMethod mMethod, QVariant value); - bool checkCustomPropertiesAndCallFunction(QObject *obj, bool (UiGuiSettings::*callBackFunc)(QObject *obj, const QString &propertyName, const QString &settingName)); - -private slots: - void handleObjectPropertyChange(); - -private: - void readAvailableTranslations(); - - //! Stores the mnemonics of the available translations. - QStringList _availableTranslations; - - //! The settings file. - QSettings *_qsettings; - - //! Maps an QObject to a string list containing the property name and the associated setting name. - QMap _registeredObjectProperties; - - //! Maps QObjects to a string list containing the method name and the associated setting name. - QMultiMap _registeredObjectSlots; - - QString _indenterDirctoryStr; -}; - -#endif // UIGUISETTINGS_H +/*************************************************************************** +* Copyright (C) 2006-2012 by Thomas Schweitzer * +* thomas-schweitzer(at)arcor.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License version 2.0 as * +* published by the Free Software Foundation. * +* * +* 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 in the file LICENSE.GPL; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#ifndef UIGUISETTINGS_H +#define UIGUISETTINGS_H + +#include +#include +#include +#include + +class QSettings; + + +class UiGuiSettings : public QObject +{ + Q_OBJECT +private: + UiGuiSettings(); + static QWeakPointer _instance; + +public: + static QSharedPointer getInstance(); + ~UiGuiSettings(); + + bool registerObjectProperty(QObject *obj, const QString &propertyName, const QString &settingName); + bool registerObjectPropertyRecursive(QObject *obj); + bool setObjectPropertyToSettingValue(QObject *obj, const QString &propertyName, const QString &settingName); + bool setObjectPropertyToSettingValueRecursive(QObject *obj); + bool setSettingToObjectPropertyValue(QObject *obj, const QString &propertyName, const QString &settingName); + bool setSettingToObjectPropertyValueRecursive(QObject *obj); + bool registerObjectSlot(QObject *obj, const QString &slotName, const QString &settingName); + QVariant getValueByName(QString settingName); + QStringList getAvailableTranslations(); + +public slots: + void setValueByName(const QString &settingName, const QVariant &value); + void unregisterObjectProperty(QObject *obj); + void unregisterObjectSlot(QObject *obj, const QString &slotName = "", const QString &settingName = ""); + +protected: + bool initSettings(); + bool invokeMethodWithValue(QObject *obj, QMetaMethod mMethod, QVariant value); + bool checkCustomPropertiesAndCallFunction(QObject *obj, bool (UiGuiSettings::*callBackFunc)(QObject *obj, const QString &propertyName, const QString &settingName)); + +private slots: + void handleObjectPropertyChange(); + +private: + void readAvailableTranslations(); + + //! Stores the mnemonics of the available translations. + QStringList _availableTranslations; + + //! The settings file. + QSettings *_qsettings; + + //! Maps an QObject to a string list containing the property name and the associated setting name. + QMap _registeredObjectProperties; + + //! Maps QObjects to a string list containing the method name and the associated setting name. + QMultiMap _registeredObjectSlots; + + QString _indenterDirctoryStr; +}; + +#endif // UIGUISETTINGS_H diff --git a/src/UiGuiSettingsDialog.h b/src/UiGuiSettingsDialog.h index 582d436..9f53262 100755 --- a/src/UiGuiSettingsDialog.h +++ b/src/UiGuiSettingsDialog.h @@ -20,7 +20,7 @@ #ifndef UIGUISETTINGSDIALOG_H #define UIGUISETTINGSDIALOG_H -#include +#include #include "UiGuiSettings.h" diff --git a/src/UiGuiSystemInfo.cpp b/src/UiGuiSystemInfo.cpp index 6763bf8..b83a636 100755 --- a/src/UiGuiSystemInfo.cpp +++ b/src/UiGuiSystemInfo.cpp @@ -1,227 +1,227 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "UiGuiSystemInfo.h" - -#include -#include -#include -#include - -UiGuiSystemInfo::UiGuiSystemInfo() { -} - - -/*! - \brief Returns the operating system UiGUI is currently running on as one string. - - The String contains name and version of the os. E.g. Linux Ubuntu 9.04. - */ -QString UiGuiSystemInfo::getOperatingSystem() { - QString operatingSystemString = ""; - -#if defined(Q_WS_WIN) - switch ( QSysInfo::WindowsVersion ) { - case QSysInfo::WV_32s : - operatingSystemString = "Windows 3.1 with Win 32s"; - break; - case QSysInfo::WV_95 : - operatingSystemString = "Windows 95"; - break; - case QSysInfo::WV_98 : - operatingSystemString = "Windows 98"; - break; - case QSysInfo::WV_Me : - operatingSystemString = "Windows Me"; - break; - case QSysInfo::WV_NT : - operatingSystemString = "Windows NT (operating system version 4.0)"; - break; - case QSysInfo::WV_2000 : - operatingSystemString = "Windows 2000 (operating system version 5.0)"; - break; - case QSysInfo::WV_XP : - operatingSystemString = "Windows XP (operating system version 5.1)"; - break; - case QSysInfo::WV_2003 : - operatingSystemString = "Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)"; - break; - case QSysInfo::WV_VISTA : - operatingSystemString = "Windows Vista, Windows Server 2008 (operating system version 6.0)"; - break; - case QSysInfo::WV_WINDOWS7 : - operatingSystemString = "Windows 7 (operating system version 6.1)"; - break; - case QSysInfo::WV_CE : - operatingSystemString = "Windows CE"; - break; - case QSysInfo::WV_CENET : - operatingSystemString = "Windows CE .NET"; - break; - case QSysInfo::WV_CE_5 : - operatingSystemString = "Windows CE 5.x"; - break; - case QSysInfo::WV_CE_6 : - operatingSystemString = "Windows CE 6.x"; - break; - default : - operatingSystemString = "Unknown Windows operating system."; - break; - } -#elif defined(Q_WS_MAC) - switch ( QSysInfo::MacintoshVersion ) { - case QSysInfo::MV_9 : - operatingSystemString = "Mac OS 9 (unsupported)"; - break; - case QSysInfo::MV_10_0 : - operatingSystemString = "Mac OS X 10.0 Cheetah (unsupported)"; - break; - case QSysInfo::MV_10_1 : - operatingSystemString = "Mac OS X 10.1 Puma (unsupported)"; - break; - case QSysInfo::MV_10_2 : - operatingSystemString = "Mac OS X 10.2 Jaguar (unsupported)"; - break; - case QSysInfo::MV_10_3 : - operatingSystemString = "Mac OS X 10.3 Panther"; - break; - case QSysInfo::MV_10_4 : - operatingSystemString = "Mac OS X 10.4 Tiger"; - break; - case QSysInfo::MV_10_5 : - operatingSystemString = "Mac OS X 10.5 Leopard"; - break; - case QSysInfo::MV_10_6 : - operatingSystemString = "Mac OS X 10.6 Snow Leopard"; - break; - case QSysInfo::MV_Unknown : - operatingSystemString = "An unknown and currently unsupported platform"; - break; - default : - operatingSystemString = "Unknown Mac operating system."; - break; - } -#else - //TODO: Detect Unix, Linux etc. distro as described on http://www.novell.com/coolsolutions/feature/11251.html - operatingSystemString = "Linux"; - QProcess process; - - process.start("uname -s"); - bool result = process.waitForFinished(1000); - QString os = process.readAllStandardOutput().trimmed(); - - process.start("uname -r"); - result = process.waitForFinished(1000); - QString rev = process.readAllStandardOutput().trimmed(); - - process.start("uname -m"); - result = process.waitForFinished(1000); - QString mach = process.readAllStandardOutput().trimmed(); - - if ( os == "SunOS" ) { - os = "Solaris"; - - process.start("uname -p"); - result = process.waitForFinished(1000); - QString arch = process.readAllStandardOutput().trimmed(); - - process.start("uname -v"); - result = process.waitForFinished(1000); - QString timestamp = process.readAllStandardOutput().trimmed(); - - operatingSystemString = os + " " + rev + " (" + arch + " " + timestamp + ")"; - } - else if ( os == "AIX" ) { - process.start("oslevel -r"); - result = process.waitForFinished(1000); - QString oslevel = process.readAllStandardOutput().trimmed(); - - operatingSystemString = os + "oslevel " + oslevel; - } - else if ( os == "Linux" ) { - QString dist; - QString pseudoname; - QString kernel = rev; - - if ( QFile::exists("/etc/redhat-release") ) { - dist = "RedHat"; - - process.start("sh -c \"cat /etc/redhat-release | sed s/.*\\(// | sed s/\\)//\""); - result = process.waitForFinished(1000); - pseudoname = process.readAllStandardOutput().trimmed(); - - process.start("sh -c \"cat /etc/redhat-release | sed s/.*release\\ // | sed s/\\ .*//\""); - result = process.waitForFinished(1000); - rev = process.readAllStandardOutput().trimmed(); - } - else if ( QFile::exists("/etc/SUSE-release") ) { - process.start("sh -c \"cat /etc/SUSE-release | tr '\\n' ' '| sed s/VERSION.*//\""); - result = process.waitForFinished(1000); - dist = process.readAllStandardOutput().trimmed(); - - process.start("sh -c \"cat /etc/SUSE-release | tr '\\n' ' ' | sed s/.*=\\ //\""); - result = process.waitForFinished(1000); - rev = process.readAllStandardOutput().trimmed(); - } - else if ( QFile::exists("/etc/mandrake-release") ) { - dist = "Mandrake"; - - process.start("sh -c \"cat /etc/mandrake-release | sed s/.*\\(// | sed s/\\)//\""); - result = process.waitForFinished(1000); - pseudoname = process.readAllStandardOutput().trimmed(); - - process.start("sh -c \"cat /etc/mandrake-release | sed s/.*release\\ // | sed s/\\ .*//\""); - result = process.waitForFinished(1000); - rev = process.readAllStandardOutput().trimmed(); - } - else if ( QFile::exists("/etc/lsb-release") ) { - dist = "Ubuntu"; - - QString processCall = "sh -c \"cat /etc/lsb-release | tr '\\n' ' ' | sed s/.*DISTRIB_RELEASE=// | sed s/\\ .*//\""; - process.start( processCall ); - result = process.waitForFinished(1000); - rev = process.readAllStandardOutput().trimmed(); - QString errorStr = process.readAllStandardError(); - - process.start("sh -c \"cat /etc/lsb-release | tr '\\n' ' ' | sed s/.*DISTRIB_CODENAME=// | sed s/\\ .*//\""); - result = process.waitForFinished(1000); - pseudoname = process.readAllStandardOutput().trimmed(); - } - else if ( QFile::exists("/etc/debian_version") ) { - dist = "Debian"; - - process.start("cat /etc/debian_version"); - result = process.waitForFinished(1000); - dist += process.readAllStandardOutput().trimmed(); - - rev = ""; - } - - if ( QFile::exists("/etc/UnitedLinux-release") ) { - process.start("sh -c \"cat /etc/UnitedLinux-release | tr '\\n' ' ' | sed s/VERSION.*//\""); - result = process.waitForFinished(1000); - dist += process.readAllStandardOutput().trimmed(); - } - - operatingSystemString = os + " " + dist + " " + rev + " (" + pseudoname + " " + kernel + " " + mach + ")"; - } -#endif - - return operatingSystemString; -} +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "UiGuiSystemInfo.h" + +#include +#include +#include +#include + +UiGuiSystemInfo::UiGuiSystemInfo() { +} + + +/*! + \brief Returns the operating system UiGUI is currently running on as one string. + + The String contains name and version of the os. E.g. Linux Ubuntu 9.04. + */ +QString UiGuiSystemInfo::getOperatingSystem() { + QString operatingSystemString = ""; + +#if defined(Q_WS_WIN) + switch ( QSysInfo::WindowsVersion ) { + case QSysInfo::WV_32s : + operatingSystemString = "Windows 3.1 with Win 32s"; + break; + case QSysInfo::WV_95 : + operatingSystemString = "Windows 95"; + break; + case QSysInfo::WV_98 : + operatingSystemString = "Windows 98"; + break; + case QSysInfo::WV_Me : + operatingSystemString = "Windows Me"; + break; + case QSysInfo::WV_NT : + operatingSystemString = "Windows NT (operating system version 4.0)"; + break; + case QSysInfo::WV_2000 : + operatingSystemString = "Windows 2000 (operating system version 5.0)"; + break; + case QSysInfo::WV_XP : + operatingSystemString = "Windows XP (operating system version 5.1)"; + break; + case QSysInfo::WV_2003 : + operatingSystemString = "Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)"; + break; + case QSysInfo::WV_VISTA : + operatingSystemString = "Windows Vista, Windows Server 2008 (operating system version 6.0)"; + break; + case QSysInfo::WV_WINDOWS7 : + operatingSystemString = "Windows 7 (operating system version 6.1)"; + break; + case QSysInfo::WV_CE : + operatingSystemString = "Windows CE"; + break; + case QSysInfo::WV_CENET : + operatingSystemString = "Windows CE .NET"; + break; + case QSysInfo::WV_CE_5 : + operatingSystemString = "Windows CE 5.x"; + break; + case QSysInfo::WV_CE_6 : + operatingSystemString = "Windows CE 6.x"; + break; + default : + operatingSystemString = "Unknown Windows operating system."; + break; + } +#elif defined(Q_WS_MAC) + switch ( QSysInfo::MacintoshVersion ) { + case QSysInfo::MV_9 : + operatingSystemString = "Mac OS 9 (unsupported)"; + break; + case QSysInfo::MV_10_0 : + operatingSystemString = "Mac OS X 10.0 Cheetah (unsupported)"; + break; + case QSysInfo::MV_10_1 : + operatingSystemString = "Mac OS X 10.1 Puma (unsupported)"; + break; + case QSysInfo::MV_10_2 : + operatingSystemString = "Mac OS X 10.2 Jaguar (unsupported)"; + break; + case QSysInfo::MV_10_3 : + operatingSystemString = "Mac OS X 10.3 Panther"; + break; + case QSysInfo::MV_10_4 : + operatingSystemString = "Mac OS X 10.4 Tiger"; + break; + case QSysInfo::MV_10_5 : + operatingSystemString = "Mac OS X 10.5 Leopard"; + break; + case QSysInfo::MV_10_6 : + operatingSystemString = "Mac OS X 10.6 Snow Leopard"; + break; + case QSysInfo::MV_Unknown : + operatingSystemString = "An unknown and currently unsupported platform"; + break; + default : + operatingSystemString = "Unknown Mac operating system."; + break; + } +#else + //TODO: Detect Unix, Linux etc. distro as described on http://www.novell.com/coolsolutions/feature/11251.html + operatingSystemString = "Linux"; + QProcess process; + + process.start("uname -s"); + bool result = process.waitForFinished(1000); + QString os = process.readAllStandardOutput().trimmed(); + + process.start("uname -r"); + result = process.waitForFinished(1000); + QString rev = process.readAllStandardOutput().trimmed(); + + process.start("uname -m"); + result = process.waitForFinished(1000); + QString mach = process.readAllStandardOutput().trimmed(); + + if ( os == "SunOS" ) { + os = "Solaris"; + + process.start("uname -p"); + result = process.waitForFinished(1000); + QString arch = process.readAllStandardOutput().trimmed(); + + process.start("uname -v"); + result = process.waitForFinished(1000); + QString timestamp = process.readAllStandardOutput().trimmed(); + + operatingSystemString = os + " " + rev + " (" + arch + " " + timestamp + ")"; + } + else if ( os == "AIX" ) { + process.start("oslevel -r"); + result = process.waitForFinished(1000); + QString oslevel = process.readAllStandardOutput().trimmed(); + + operatingSystemString = os + "oslevel " + oslevel; + } + else if ( os == "Linux" ) { + QString dist; + QString pseudoname; + QString kernel = rev; + + if ( QFile::exists("/etc/redhat-release") ) { + dist = "RedHat"; + + process.start("sh -c \"cat /etc/redhat-release | sed s/.*\\(// | sed s/\\)//\""); + result = process.waitForFinished(1000); + pseudoname = process.readAllStandardOutput().trimmed(); + + process.start("sh -c \"cat /etc/redhat-release | sed s/.*release\\ // | sed s/\\ .*//\""); + result = process.waitForFinished(1000); + rev = process.readAllStandardOutput().trimmed(); + } + else if ( QFile::exists("/etc/SUSE-release") ) { + process.start("sh -c \"cat /etc/SUSE-release | tr '\\n' ' '| sed s/VERSION.*//\""); + result = process.waitForFinished(1000); + dist = process.readAllStandardOutput().trimmed(); + + process.start("sh -c \"cat /etc/SUSE-release | tr '\\n' ' ' | sed s/.*=\\ //\""); + result = process.waitForFinished(1000); + rev = process.readAllStandardOutput().trimmed(); + } + else if ( QFile::exists("/etc/mandrake-release") ) { + dist = "Mandrake"; + + process.start("sh -c \"cat /etc/mandrake-release | sed s/.*\\(// | sed s/\\)//\""); + result = process.waitForFinished(1000); + pseudoname = process.readAllStandardOutput().trimmed(); + + process.start("sh -c \"cat /etc/mandrake-release | sed s/.*release\\ // | sed s/\\ .*//\""); + result = process.waitForFinished(1000); + rev = process.readAllStandardOutput().trimmed(); + } + else if ( QFile::exists("/etc/lsb-release") ) { + dist = "Ubuntu"; + + QString processCall = "sh -c \"cat /etc/lsb-release | tr '\\n' ' ' | sed s/.*DISTRIB_RELEASE=// | sed s/\\ .*//\""; + process.start( processCall ); + result = process.waitForFinished(1000); + rev = process.readAllStandardOutput().trimmed(); + QString errorStr = process.readAllStandardError(); + + process.start("sh -c \"cat /etc/lsb-release | tr '\\n' ' ' | sed s/.*DISTRIB_CODENAME=// | sed s/\\ .*//\""); + result = process.waitForFinished(1000); + pseudoname = process.readAllStandardOutput().trimmed(); + } + else if ( QFile::exists("/etc/debian_version") ) { + dist = "Debian"; + + process.start("cat /etc/debian_version"); + result = process.waitForFinished(1000); + dist += process.readAllStandardOutput().trimmed(); + + rev = ""; + } + + if ( QFile::exists("/etc/UnitedLinux-release") ) { + process.start("sh -c \"cat /etc/UnitedLinux-release | tr '\\n' ' ' | sed s/VERSION.*//\""); + result = process.waitForFinished(1000); + dist += process.readAllStandardOutput().trimmed(); + } + + operatingSystemString = os + " " + dist + " " + rev + " (" + pseudoname + " " + kernel + " " + mach + ")"; + } +#endif + + return operatingSystemString; +} diff --git a/src/UiGuiSystemInfo.h b/src/UiGuiSystemInfo.h index 08dca5b..3ed56ca 100755 --- a/src/UiGuiSystemInfo.h +++ b/src/UiGuiSystemInfo.h @@ -1,35 +1,35 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef UIGUISYSTEMINFO_H -#define UIGUISYSTEMINFO_H - -class QString; - - -class UiGuiSystemInfo -{ -public: - static QString getOperatingSystem(); - -private: - UiGuiSystemInfo(); -}; - -#endif // UIGUISYSTEMINFO_H +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef UIGUISYSTEMINFO_H +#define UIGUISYSTEMINFO_H + +class QString; + + +class UiGuiSystemInfo +{ +public: + static QString getOperatingSystem(); + +private: + UiGuiSystemInfo(); +}; + +#endif // UIGUISYSTEMINFO_H diff --git a/src/UiGuiVersion.cpp b/src/UiGuiVersion.cpp index 375df0e..8ddcdd8 100755 --- a/src/UiGuiVersion.cpp +++ b/src/UiGuiVersion.cpp @@ -1,61 +1,61 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "UiGuiVersion.h" - -#include -#include -#include - -namespace UiGuiVersion { -/*! - \brief Returns the build date as a localized string, e.g. "9. Februar 2009". If - there was some kind of error, the returned string is empty. - */ -QString getBuildDate() { - QStringList monthNames; - QString buildDateString = ""; - - monthNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dez"; - QStringList buildDateStringList = QString(__DATE__).simplified().split(' '); // __DATE__ returns eg "Feb 4 2009" - - if ( buildDateStringList.count() == 3 ) { - QDate buildDate(buildDateStringList.last().toInt(), monthNames.indexOf( buildDateStringList.first() )+1, buildDateStringList.at(1).toInt()); - buildDateString = buildDate.toString("d. MMMM yyyy"); - } - - return buildDateString; -} - - -/*! - \brief Returns the revision number, that the current build is based on, as string. If - there was some kind of error, the returned string is empty. - */ -QString getBuildRevision() { - QString buildRevision = ""; - QStringList buildRevisionStringList = QString(PROGRAM_REVISION).simplified().split(' '); - - if ( buildRevisionStringList.count() == 3 ) { - buildRevision = buildRevisionStringList.at(1); // PROGRAM_REVISION is eg "$Revision: 907 $" - } - - return buildRevision; -} -} // namespace UiGuiVersion +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "UiGuiVersion.h" + +#include +#include +#include + +namespace UiGuiVersion { +/*! + \brief Returns the build date as a localized string, e.g. "9. Februar 2009". If + there was some kind of error, the returned string is empty. + */ +QString getBuildDate() { + QStringList monthNames; + QString buildDateString = ""; + + monthNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dez"; + QStringList buildDateStringList = QString(__DATE__).simplified().split(' '); // __DATE__ returns eg "Feb 4 2009" + + if ( buildDateStringList.count() == 3 ) { + QDate buildDate(buildDateStringList.last().toInt(), monthNames.indexOf( buildDateStringList.first() )+1, buildDateStringList.at(1).toInt()); + buildDateString = buildDate.toString("d. MMMM yyyy"); + } + + return buildDateString; +} + + +/*! + \brief Returns the revision number, that the current build is based on, as string. If + there was some kind of error, the returned string is empty. + */ +QString getBuildRevision() { + QString buildRevision = ""; + QStringList buildRevisionStringList = QString(PROGRAM_REVISION).simplified().split(' '); + + if ( buildRevisionStringList.count() == 3 ) { + buildRevision = buildRevisionStringList.at(1); // PROGRAM_REVISION is eg "$Revision: 907 $" + } + + return buildRevision; +} +} // namespace UiGuiVersion diff --git a/src/UiGuiVersion.h b/src/UiGuiVersion.h index 41aff77..696313f 100755 --- a/src/UiGuiVersion.h +++ b/src/UiGuiVersion.h @@ -1,39 +1,39 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef UIGUIVERSION_H -#define UIGUIVERSION_H - -class QString; - -// Define the version number here. Update this as the last file before a release. -#define PROGRAM_VERSION 1.2.0 -#define PROGRAM_VERSION_STRING "1.2.0" -#define RESOURCE_VERSION 1,2,0,0 -#define RESOURCE_VERSION_STRING "1,2,0,0\0" -#define PROGRAM_REVISION "$Revision: 1070 $" - -namespace UiGuiVersion { - - QString getBuildDate(); - QString getBuildRevision(); - -} - -#endif // UIGUIVERSION_H +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef UIGUIVERSION_H +#define UIGUIVERSION_H + +class QString; + +// Define the version number here. Update this as the last file before a release. +#define PROGRAM_VERSION 1.2.0 +#define PROGRAM_VERSION_STRING "1.2.0" +#define RESOURCE_VERSION 1,2,0,0 +#define RESOURCE_VERSION_STRING "1,2,0,0\0" +#define PROGRAM_REVISION "$Revision: 1070 $" + +namespace UiGuiVersion { + + QString getBuildDate(); + QString getBuildRevision(); + +} + +#endif // UIGUIVERSION_H diff --git a/src/UpdateCheckDialog.cpp b/src/UpdateCheckDialog.cpp index a5a58d8..9a352a7 100755 --- a/src/UpdateCheckDialog.cpp +++ b/src/UpdateCheckDialog.cpp @@ -23,16 +23,16 @@ #include "UiGuiSettings.h" #include "UiGuiVersion.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /*! \class UpdateCheckDialog diff --git a/src/UpdateCheckDialog.h b/src/UpdateCheckDialog.h index f0dfe81..85082cd 100755 --- a/src/UpdateCheckDialog.h +++ b/src/UpdateCheckDialog.h @@ -1,73 +1,73 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef UPDATECHECKDIALOG_H -#define UPDATECHECKDIALOG_H - -#include -#include - -class UiGuiSettings; -namespace Ui { - class UpdateCheckDialog; -} - -class QTimer; -class QDesktopServices; -class QNetworkAccessManager; -class QNetworkReply; - - -class UpdateCheckDialog : public QDialog -{ - Q_OBJECT - -public: - UpdateCheckDialog(QSharedPointer settings, QWidget *parent = NULL); - ~UpdateCheckDialog(); - -public slots: - void checkForUpdateAndShowDialog(); - void checkForUpdate(); - -private slots: - void checkResultsOfFetchedPadXMLFile(QNetworkReply *networkReply); - void handleUpdateCheckDialogButtonClicked(QAbstractButton *clickedButton); - void updateUpdateCheckProgressBar(); - void initProxySettings(); - -private: - Ui::UpdateCheckDialog *_updateCheckDialogForm; - - void getPadXMLFile(); - void showCheckingForUpdateDialog(); - void showNewVersionAvailableDialog(QString newVersion); - void showNoNewVersionAvailableDialog(); - int convertVersionStringToNumber(QString versionString); - - QSharedPointer _settings; - bool _manualUpdateRequested; - QNetworkAccessManager *_networkAccessManager; - QNetworkReply *_currentNetworkReply; - QDialogButtonBox::ButtonRole _roleOfClickedButton; - QTimer *_updateCheckProgressTimer; - int _updateCheckProgressCounter; -}; - -#endif // UPDATECHECKDIALOG_H +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef UPDATECHECKDIALOG_H +#define UPDATECHECKDIALOG_H + +#include +#include + +class UiGuiSettings; +namespace Ui { + class UpdateCheckDialog; +} + +class QTimer; +class QDesktopServices; +class QNetworkAccessManager; +class QNetworkReply; + + +class UpdateCheckDialog : public QDialog +{ + Q_OBJECT + +public: + UpdateCheckDialog(QSharedPointer settings, QWidget *parent = NULL); + ~UpdateCheckDialog(); + +public slots: + void checkForUpdateAndShowDialog(); + void checkForUpdate(); + +private slots: + void checkResultsOfFetchedPadXMLFile(QNetworkReply *networkReply); + void handleUpdateCheckDialogButtonClicked(QAbstractButton *clickedButton); + void updateUpdateCheckProgressBar(); + void initProxySettings(); + +private: + Ui::UpdateCheckDialog *_updateCheckDialogForm; + + void getPadXMLFile(); + void showCheckingForUpdateDialog(); + void showNewVersionAvailableDialog(QString newVersion); + void showNoNewVersionAvailableDialog(); + int convertVersionStringToNumber(QString versionString); + + QSharedPointer _settings; + bool _manualUpdateRequested; + QNetworkAccessManager *_networkAccessManager; + QNetworkReply *_currentNetworkReply; + QDialogButtonBox::ButtonRole _roleOfClickedButton; + QTimer *_updateCheckProgressTimer; + int _updateCheckProgressCounter; +}; + +#endif // UPDATECHECKDIALOG_H diff --git a/src/debugging/TSLogger.cpp b/src/debugging/TSLogger.cpp index e7a912b..a13113e 100755 --- a/src/debugging/TSLogger.cpp +++ b/src/debugging/TSLogger.cpp @@ -1,251 +1,251 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * 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 in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "TSLogger.h" -#include "ui_TSLoggerDialog.h" - -#include "SettingsPaths.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace tschweitzer; -using namespace tschweitzer::debugging; - -TSLogger* TSLogger::_instance = NULL; - -/*! - \class TSLogger - \brief This class handles any kind of data logging, for debugging and whatever purpose. - - Beneath being able of displaying a dialog window containing all log messages of the - current session, a log file in the systems temporary directory is used. Its name - is "UiGUI_log.html". - - Setting a verbose level allows to only write messages that have the selected minimum - priority to the log. - */ - -/*! - \brief Returns the only existing instance of TSLogger. If the instance doesn't exist, it will be created. - */ -TSLogger* TSLogger::getInstance(int verboseLevel) { - if ( _instance == NULL ) - _instance = new TSLogger(verboseLevel); - - return _instance; -} - - -/*! - \brief Returns the only existing instance of TSLogger. If the instance doesn't exist, it will be created. - */ -TSLogger* TSLogger::getInstance() { -#ifdef _DEBUG - return TSLogger::getInstance(QtDebugMsg); -#else - return TSLogger::getInstance(QtWarningMsg); -#endif -} - - -/*! - \brief Initializes the dialog and sets the path to the log file in the systems temporary directory. - Sets the default verbose level to warning level. - */ -TSLogger::TSLogger(int verboseLevel) : QDialog() { - _TSLoggerDialogForm = new Ui::TSLoggerDialog(); - _TSLoggerDialogForm->setupUi(this); -#ifdef _DEBUG - _verboseLevel = QtDebugMsg; -#else - _verboseLevel = QtMsgType(verboseLevel); -#endif - - _logFileInitState = NOTINITIALZED; - - connect( _TSLoggerDialogForm->openLogFileFolderToolButton, SIGNAL(clicked()), this, SLOT(openLogFileFolder()) ); - - // Make the main application not to wait for the logging window to close. - setAttribute(Qt::WA_QuitOnClose, false); -} - - -/*! - \brief Logs all incoming messages \a msg to the dialogs text edit and to the log file. - - Only messages whos \a type have a higher priority than the set verbose level are logged. - */ -void TSLogger::messageHandler(QtMsgType type, const char *msg) { - if ( _instance == NULL ) - _instance = TSLogger::getInstance(); - -/* - QMessageBox messageBox; - QString messageBoxText = QString::fromUtf8( msg ); - messageBox.setText( messageBoxText ); - messageBox.setWindowModality( Qt::ApplicationModal ); - messageBox.exec(); -*/ - - // Only log messages that have a higher or equal priority than set with the verbose level. - if ( type < _instance->_verboseLevel ) - return; - - // Init log message with prepended date and time. - QString message = QDateTime::currentDateTime().toString(); - - // Depending on the QtMsgType prepend a different colored Debug, Warning, Critical or Fatal. - switch (type) { - case QtDebugMsg : - message += " Debug: "; - break; - case QtWarningMsg : - message += " Warning: "; - break; - case QtCriticalMsg : - message += "Critical: "; - break; - case QtFatalMsg : - message += " Fatal: "; - // This one is no Qt message type, but can be used to send info messages to the log - // by calling TSLogger::messageHandler() directly. - case TSLoggerInfoMsg : - message += " Info: "; - break; - } - - // Append the to UTF-8 back converted message parameter. - message += QString::fromUtf8( msg ) + "
\n"; - - // Write the message to the log windows text edit. - _instance->_TSLoggerDialogForm->logTextEdit->append( message ); - - // Write/append the log message to the log file. - _instance->writeToLogFile( message ); - - // In case of a fatal error abort the application. - if ( type == QtFatalMsg ) - abort(); -} - - -/*! - \brief Calling this the verbose level can be set in a range from 0 to 3 - which is equal to debug, warning, critical and fatal priority. - */ -void TSLogger::setVerboseLevel(int level) { - if ( level < 0 ) - _verboseLevel = QtDebugMsg; - if ( level > 3 ) - _verboseLevel = QtFatalMsg; - else - _verboseLevel = QtMsgType(level); -} - - -/*! - \brief Deletes the existing _instance of TSLogger. - */ -void TSLogger::deleteInstance() { - if ( _instance != NULL ) { - delete _instance; - _instance = NULL; - } -} - - -/*! - \brief Opens the folder that contains the created log file with the name "UiGUI_log.html". - */ -void TSLogger::openLogFileFolder() { - QDesktopServices::openUrl( QFileInfo( _logFile ).absolutePath() ); -} - - -/*! - \brief Writes the \a message to the used log file. - */ -void TSLogger::writeToLogFile(const QString &message) { - // If the file where all logging messages should go to isn't initilized yet, do that now. - if ( _logFileInitState == NOTINITIALZED ) { - _logFileInitState = INITIALIZING; - - // On different systems it may be that "QDir::tempPath()" ends with a "/" or not. So check this. - // Remove any trailing slashes. - QString tempPath = QFileInfo( SettingsPaths::getTempPath() ).absolutePath(); - while ( tempPath.right(1) == "/" ) { - tempPath.chop(1); - } - - // To make the temporary log file invulnerable against file symbolic link hacks - // append the current date and time up to milliseconds to its name and a random character. - QString logFileName = "UiGUI_log_" + QDateTime::currentDateTime().toString("yyyyMMdd"); - logFileName += "-" + QDateTime::currentDateTime().toString("hhmmsszzz"); - // By random decide whether to append a number or an upper or lower case character. - qsrand( time(NULL) ); - unsigned char randomChar; - switch ( qrand() % 3 ) { - // Append a number from 0 to 9. - case 0 : - randomChar = qrand() % 10 + '0'; - break; - // Append a upper case characer between A and Z. - case 1 : - randomChar = qrand() % 26 + 'A'; - break; - // Append a lower case characer between a and z. - default : - randomChar = qrand() % 26 + 'a'; - break; - } - logFileName += "_" + QString(randomChar) + ".html"; - - _logFile.setFileName( tempPath + "/" + logFileName ); - - // Set the tooltip of the open log file folder button to show the unique name of the log file. - _TSLoggerDialogForm->openLogFileFolderToolButton->setToolTip( _TSLoggerDialogForm->openLogFileFolderToolButton->toolTip() + " (" + logFileName + ")" ); - - _logFileInitState = INITIALZED; - } - - // Add the message to the message queue. - _messageQueue << message; - - // If the logging file is initialzed, write all messages contained in the message queue into the file. - if ( _logFileInitState == INITIALZED ) { - // Write/append the log message to the log file. - if ( _logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append) ) { - QTextStream out(&_logFile); - - while ( !_messageQueue.isEmpty() ) { - out << _messageQueue.takeFirst() << "\n"; - } - - _logFile.close(); - } - } -} +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * 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 in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "TSLogger.h" +#include "ui_TSLoggerDialog.h" + +#include "SettingsPaths.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace tschweitzer; +using namespace tschweitzer::debugging; + +TSLogger* TSLogger::_instance = NULL; + +/*! + \class TSLogger + \brief This class handles any kind of data logging, for debugging and whatever purpose. + + Beneath being able of displaying a dialog window containing all log messages of the + current session, a log file in the systems temporary directory is used. Its name + is "UiGUI_log.html". + + Setting a verbose level allows to only write messages that have the selected minimum + priority to the log. + */ + +/*! + \brief Returns the only existing instance of TSLogger. If the instance doesn't exist, it will be created. + */ +TSLogger* TSLogger::getInstance(int verboseLevel) { + if ( _instance == NULL ) + _instance = new TSLogger(verboseLevel); + + return _instance; +} + + +/*! + \brief Returns the only existing instance of TSLogger. If the instance doesn't exist, it will be created. + */ +TSLogger* TSLogger::getInstance() { +#ifdef _DEBUG + return TSLogger::getInstance(QtDebugMsg); +#else + return TSLogger::getInstance(QtWarningMsg); +#endif +} + + +/*! + \brief Initializes the dialog and sets the path to the log file in the systems temporary directory. + Sets the default verbose level to warning level. + */ +TSLogger::TSLogger(int verboseLevel) : QDialog() { + _TSLoggerDialogForm = new Ui::TSLoggerDialog(); + _TSLoggerDialogForm->setupUi(this); +#ifdef _DEBUG + _verboseLevel = QtDebugMsg; +#else + _verboseLevel = QtMsgType(verboseLevel); +#endif + + _logFileInitState = NOTINITIALZED; + + connect( _TSLoggerDialogForm->openLogFileFolderToolButton, SIGNAL(clicked()), this, SLOT(openLogFileFolder()) ); + + // Make the main application not to wait for the logging window to close. + setAttribute(Qt::WA_QuitOnClose, false); +} + + +/*! + \brief Logs all incoming messages \a msg to the dialogs text edit and to the log file. + + Only messages whos \a type have a higher priority than the set verbose level are logged. + */ +void TSLogger::messageHandler(QtMsgType type, const char *msg) { + if ( _instance == NULL ) + _instance = TSLogger::getInstance(); + +/* + QMessageBox messageBox; + QString messageBoxText = QString::fromUtf8( msg ); + messageBox.setText( messageBoxText ); + messageBox.setWindowModality( Qt::ApplicationModal ); + messageBox.exec(); +*/ + + // Only log messages that have a higher or equal priority than set with the verbose level. + if ( type < _instance->_verboseLevel ) + return; + + // Init log message with prepended date and time. + QString message = QDateTime::currentDateTime().toString(); + + // Depending on the QtMsgType prepend a different colored Debug, Warning, Critical or Fatal. + switch (type) { + case QtDebugMsg : + message += " Debug: "; + break; + case QtWarningMsg : + message += " Warning: "; + break; + case QtCriticalMsg : + message += "Critical: "; + break; + case QtFatalMsg : + message += " Fatal: "; + // This one is no Qt message type, but can be used to send info messages to the log + // by calling TSLogger::messageHandler() directly. + case TSLoggerInfoMsg : + message += " Info: "; + break; + } + + // Append the to UTF-8 back converted message parameter. + message += QString::fromUtf8( msg ) + "
\n"; + + // Write the message to the log windows text edit. + _instance->_TSLoggerDialogForm->logTextEdit->append( message ); + + // Write/append the log message to the log file. + _instance->writeToLogFile( message ); + + // In case of a fatal error abort the application. + if ( type == QtFatalMsg ) + abort(); +} + + +/*! + \brief Calling this the verbose level can be set in a range from 0 to 3 + which is equal to debug, warning, critical and fatal priority. + */ +void TSLogger::setVerboseLevel(int level) { + if ( level < 0 ) + _verboseLevel = QtDebugMsg; + if ( level > 3 ) + _verboseLevel = QtFatalMsg; + else + _verboseLevel = QtMsgType(level); +} + + +/*! + \brief Deletes the existing _instance of TSLogger. + */ +void TSLogger::deleteInstance() { + if ( _instance != NULL ) { + delete _instance; + _instance = NULL; + } +} + + +/*! + \brief Opens the folder that contains the created log file with the name "UiGUI_log.html". + */ +void TSLogger::openLogFileFolder() { + QDesktopServices::openUrl( QFileInfo( _logFile ).absolutePath() ); +} + + +/*! + \brief Writes the \a message to the used log file. + */ +void TSLogger::writeToLogFile(const QString &message) { + // If the file where all logging messages should go to isn't initilized yet, do that now. + if ( _logFileInitState == NOTINITIALZED ) { + _logFileInitState = INITIALIZING; + + // On different systems it may be that "QDir::tempPath()" ends with a "/" or not. So check this. + // Remove any trailing slashes. + QString tempPath = QFileInfo( SettingsPaths::getTempPath() ).absolutePath(); + while ( tempPath.right(1) == "/" ) { + tempPath.chop(1); + } + + // To make the temporary log file invulnerable against file symbolic link hacks + // append the current date and time up to milliseconds to its name and a random character. + QString logFileName = "UiGUI_log_" + QDateTime::currentDateTime().toString("yyyyMMdd"); + logFileName += "-" + QDateTime::currentDateTime().toString("hhmmsszzz"); + // By random decide whether to append a number or an upper or lower case character. + qsrand( time(NULL) ); + unsigned char randomChar; + switch ( qrand() % 3 ) { + // Append a number from 0 to 9. + case 0 : + randomChar = qrand() % 10 + '0'; + break; + // Append a upper case characer between A and Z. + case 1 : + randomChar = qrand() % 26 + 'A'; + break; + // Append a lower case characer between a and z. + default : + randomChar = qrand() % 26 + 'a'; + break; + } + logFileName += "_" + QString(randomChar) + ".html"; + + _logFile.setFileName( tempPath + "/" + logFileName ); + + // Set the tooltip of the open log file folder button to show the unique name of the log file. + _TSLoggerDialogForm->openLogFileFolderToolButton->setToolTip( _TSLoggerDialogForm->openLogFileFolderToolButton->toolTip() + " (" + logFileName + ")" ); + + _logFileInitState = INITIALZED; + } + + // Add the message to the message queue. + _messageQueue << message; + + // If the logging file is initialzed, write all messages contained in the message queue into the file. + if ( _logFileInitState == INITIALZED ) { + // Write/append the log message to the log file. + if ( _logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append) ) { + QTextStream out(&_logFile); + + while ( !_messageQueue.isEmpty() ) { + out << _messageQueue.takeFirst() << "\n"; + } + + _logFile.close(); + } + } +} diff --git a/src/debugging/TSLogger.h b/src/debugging/TSLogger.h index c7e7e62..97268f7 100755 --- a/src/debugging/TSLogger.h +++ b/src/debugging/TSLogger.h @@ -20,8 +20,8 @@ #ifndef TSLogger_H #define TSLogger_H -#include -#include +#include +#include namespace Ui { class TSLoggerDialog; diff --git a/src/main.cpp b/src/main.cpp index 6e09f3e..77e3444 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,9 +28,9 @@ #include "IndentHandler.h" #include "SettingsPaths.h" -#include -#include -#include +#include +#include +#include #include #include -- cgit v1.2.3