From: <mrj...@us...> - 2007-10-10 04:20:14
|
Revision: 2239 http://tora.svn.sourceforge.net/tora/?rev=2239&view=rev Author: mrjohnson0 Date: 2007-10-09 21:20:18 -0700 (Tue, 09 Oct 2007) Log Message: ----------- remove CRegistry and use c calls Modified Paths: -------------- branches/tora-1.4/tora/src/utils.cpp Modified: branches/tora-1.4/tora/src/utils.cpp =================================================================== --- branches/tora-1.4/tora/src/utils.cpp 2007-10-10 04:19:49 UTC (rev 2238) +++ branches/tora-1.4/tora/src/utils.cpp 2007-10-10 04:20:18 UTC (rev 2239) @@ -49,6 +49,7 @@ #include "totool.h" #include <stdlib.h> +#include <algorithm> #include <qapplication.h> #include <qcombobox.h> @@ -71,9 +72,12 @@ //Added by qt3to4: #include <QKeyEvent> #include <QPixmap> +#include <QBrush> +#include <QColor> -#ifdef WIN32 -#include "windows/cregistry.h" +#ifdef Q_OS_WIN32 +# include "windows.h" +# include "winreg.h" #endif #if defined(Q_OS_MACX) @@ -308,7 +312,7 @@ void toStatusMessage(const QString &str, bool save, bool log) { -#ifndef WIN32 +#ifndef Q_OS_WIN32 if (!toThread::mainThread()){ return ; } @@ -503,6 +507,7 @@ Q3DockWindow *dock = new Q3DockWindow(Q3DockWindow::InDock, toMainWidget()); dock->setNewLine(true); dock->setCloseMode(Q3DockWindow::Always); + dock->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); return dock; } @@ -544,38 +549,36 @@ QString toPluginPath(void) { QString str; -#ifdef WIN32 - CRegistry registry; - DWORD siz = 1024; +#ifdef Q_OS_WIN32 + LONG siz = 1024; char buffer[1024]; - try - { - if (registry.GetStringValue(HKEY_LOCAL_MACHINE, - "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TOra", - "UninstallString", - buffer, siz)) - { - if (siz > 0) - { - str = buffer; - static QRegExp findQuotes("\"([^\"]*)\""); - if (findQuotes.search(str) >= 0) - str = findQuotes.cap(1); - int ind = str.findRev('\\'); - if (ind >= 0) - str = str.mid(0, ind); + + try { + HKEY key = NULL; + if(RegOpenKeyA(HKEY_LOCAL_MACHINE, + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TOra", + &key) == ERROR_SUCCESS) { + if(RegQueryValueA(key, + "UninstallString", + buffer, + &siz) == ERROR_SUCCESS) { + if (siz > 0) { + str = buffer; + static QRegExp findQuotes("\"([^\"]*)\""); + if (findQuotes.search(str) >= 0) + str = findQuotes.cap(1); + int ind = str.findRev('\\'); + if (ind >= 0) + str = str.mid(0, ind); + } } } } catch (...) {} + #elif defined( Q_OS_MACX ) - - - - - { // MacOS char resourcePath[MAXPATHLEN]; memset( &resourcePath[0], 0, MAXPATHLEN ); @@ -608,6 +611,7 @@ // QString( "Unexpected: unable to get main bundle") ); } } // MacOS + #else str = toConfigurationSingle::Instance().globalConfig(CONF_PLUGIN_DIR, DEFAULT_PLUGIN_DIR); #endif @@ -626,30 +630,53 @@ return str; } +Q3CString toReadFile(const QString &filename) +{ + QString expanded = toExpandFile(filename); + QFile file(expanded); + if (!file.open(QIODevice::ReadOnly)) + throw QT_TRANSLATE_NOOP("toReadFile", "Couldn't open file %1.").arg(filename); + + int size = file.size(); + + char *buf = new char[size + 1]; + if (file.readBlock(buf, size) == -1) + { + delete[] buf; + throw QT_TRANSLATE_NOOP("toReadFile", "Encountered problems read configuration"); + } + buf[size] = 0; + Q3CString ret(buf, size + 1); + delete[] buf; + return ret; +} + QString toExpandFile(const QString &file) { QString ret(file); QString home; -#ifdef WIN32 - CRegistry registry; - DWORD siz = 1024; +#ifdef Q_OS_WIN32 + LONG siz = 1024; char buffer[1024]; - try - { - if (registry.GetStringValue(HKEY_CURRENT_USER, - "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", - "Personal", - buffer, siz)) - { - if (siz > 0) - home = buffer; + try { + HKEY key = NULL; + if(RegOpenKeyA(HKEY_CURRENT_USER, + "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", + &key) == ERROR_SUCCESS) { + if(RegQueryValueA(key, + "Personal", + buffer, + &siz) == ERROR_SUCCESS) { + if (siz > 0) + home = buffer; + } } } catch (...) {} + #else - const char *homet = getenv("HOME"); if (!homet) home = ""; @@ -661,37 +688,17 @@ return ret; } -Q3CString toReadFile(const QString &filename) -{ - QString expanded = toExpandFile(filename); - QFile file(expanded); - if (!file.open(QIODevice::ReadOnly)) - throw QT_TRANSLATE_NOOP("toReadFile", "Couldn't open file %1.").arg(filename); - - int size = file.size(); - - char *buf = new char[size + 1]; - if (file.readBlock(buf, size) == -1) - { - delete[] buf; - throw QT_TRANSLATE_NOOP("toReadFile", "Encountered problems read configuration"); - } - buf[size] = 0; - Q3CString ret(buf, size + 1); - delete[] buf; - return ret; -} - bool toWriteFile(const QString &filename, const QByteArray &data) { QString expanded = toExpandFile(filename); QFile file(expanded); if (!file.open(QIODevice::WriteOnly)) { - TOMessageBox::warning(toMainWidget(), - QT_TRANSLATE_NOOP("toWriteFile", "File error"), - QT_TRANSLATE_NOOP("toWriteFile", - QString::fromLatin1("Couldn't open %1 for writing").arg(filename))); + TOMessageBox::warning( + toMainWidget(), + QT_TRANSLATE_NOOP("toWriteFile", "File error"), + QT_TRANSLATE_NOOP("toWriteFile", + QString::fromLatin1("Couldn't open %1 for writing").arg(filename))); return false; } file.writeBlock(data, data.length()); @@ -710,12 +717,12 @@ return toWriteFile(filename, data.local8Bit()); } -bool toCompareLists(QStringList &lst1, QStringList &lst2, unsigned int len) +bool toCompareLists(QStringList &lista, QStringList &lstb, unsigned int len) { - if (lst1.count() < len || lst2.count() < len) + if (lista.count() < len || lstb.count() < len) return false; for (int i = 0;i < len;i++) - if (lst1[i] != lst2[i]) + if (lista[i] != lstb[i]) return false; return true; } @@ -782,7 +789,7 @@ void toSetEnv(const Q3CString &var, const Q3CString &val) { -#if HAVE_SETENV && !defined(WIN32) +#if HAVE_SETENV && !defined(Q_OS_WIN32) setenv(var, val, 1); #else // Has a memory leak, but just a minor one. @@ -797,7 +804,7 @@ void toUnSetEnv(const Q3CString &var) { -#if HAVE_SETENV && !defined(WIN32) +#if HAVE_SETENV && !defined(Q_OS_WIN32) unsetenv(var); #else toSetEnv(var, ""); @@ -873,10 +880,11 @@ color += offset; - return QBrush(QColor(std::min(255, r*color*256 / (COLORS)), - std::min(255, g*color*256 / (COLORS)), - std::min(255, b*color*256 / (COLORS))), - rets); + QBrush brush(QColor(TO_MIN(255, r*color*256 / (COLORS)), + TO_MIN(255, g*color*256 / (COLORS)), + TO_MIN(255, b*color*256 / (COLORS))), + rets); + return brush; } toToolWidget *toCurrentTool(QObject *cur) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |