1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
/* BEGIN_COMMON_COPYRIGHT_HEADER
*
* TOra - An Oracle Toolkit for DBA's and developers
*
* Shared/mixed copyright is held throughout files in this product
*
* Portions Copyright (C) 2000-2001 Underscore AB
* Portions Copyright (C) 2003-2005 Quest Software, Inc.
* Portions Copyright (C) 2004-2009 Numerous Other Contributors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; only version 2 of
* the License is valid for this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* As a special exception, you have permission to link this program
* with the Oracle Client libraries and distribute executables, as long
* as you follow the requirements of the GNU GPL in regard to all of the
* software in the executable aside from Oracle client libraries.
*
* Specifically you are not permitted to link this program with the
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
* And you are not permitted to distribute binaries compiled against
* these libraries.
*
* You may link this product with any GPL'd Qt library.
*
* All trademarks belong to their respective owners.
*
* END_COMMON_COPYRIGHT_HEADER */
#include "utils.h"
#include "toabout.h"
#include "toconf.h"
#include "toconnection.h"
#include "tohighlightedtext.h"
#include "tomain.h"
#include "tosql.h"
#include "totool.h"
// qt4 in via the qtranslator
// #include "tora_toad.h"
#ifndef Q_OS_WIN32
#include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <QDateTime>
#include <memory>
#include <qapplication.h>
#include <qmessagebox.h>
#include <qtextcodec.h>
#include <QString>
#include <QTranslator>
#include <QStyleFactory>
#include <QFont>
#include <QTextCodec>
#ifndef TOMONOLITHIC
#include <dlfcn.h>
#include <tosplash.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <qlabel.h>
#include <QProgressBar>
#endif
bool toMonolithic(void)
{
#ifdef TOMONOLITHIC
return true;
#else
return false;
#endif
}
// void toUpdateIndicateEmpty(void);
int main(int argc, char **argv)
{
toConfiguration::setQSettingsEnv();
/*! \warning: Keep the code before QApplication init as small
as possible. There could be serious display issues when
you construct some Qt classes before QApplication.
It's the same for global static stuff - some instances can
break it (e.g. qscintilla lexers etc.).
*/
QApplication app(argc, argv);
QString style(toConfigurationSingle::Instance().style());
if (!style.isEmpty())
QApplication::setStyle(QStyleFactory::create(style));
// Set the default codec to use for QString
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
try
{
// qt4 if (getenv("LANG"))
// qApp->setDefaultCodec(QTextCodec::codecForName(getenv("LANG")));
QTranslator torats(0);
torats.load(toConfigurationSingle::Instance().pluginDir()/*toPluginPath()*/ + "/" + QString("tora_") + toConfigurationSingle::Instance().locale(), ".");
qApp->installTranslator(&torats);
QTranslator toadbindings(0);
if (toConfigurationSingle::Instance().toadBindings())
{
// qt4 - hot candidate for a builtin resource
// if (!toadbindings.load(tora_toad, sizeof(tora_toad)))
// printf("Internal error, couldn't load TOAD bindings");
toadbindings.load(toConfigurationSingle::Instance().pluginDir()/*toPluginPath()*/ + "/" + "tora_toad.qm");
qApp->installTranslator(&toadbindings);
}
#ifndef TOMONOLITHIC
{
toSplash splash(NULL, "About " TOAPPNAME, false);
splash.show();
std::list<QString> failed;
QString dirPath = toConfigurationSingle::Instance().pluginDir();/*toPluginPath()*/;
QDir d(dirPath, QString::fromLatin1("*.tso"), QDir::Name, QDir::Files);
if (!d.exists())
{
fprintf(stderr,
"Couldn't find PluginDir, falling back to default: %s\n",
DEFAULT_PLUGIN_DIR);
dirPath = DEFAULT_PLUGIN_DIR;
d.cd(dirPath);
if (d.exists())
toConfigurationSingle::Instance().setPluginDir(dirPath);
else
fprintf(stderr, "Invalid PluginDir.\n");
}
for (unsigned int i = 0;i < d.count();i++)
{
failed.insert(failed.end(), d.filePath(d[i]));
}
QProgressBar *progress = splash.progress();
QLabel *label = splash.label();
progress->setTotalSteps(failed.size());
progress->setProgress(1);
qApp->processEvents();
bool success;
do
{
success = false;
std::list<QString> current = failed;
failed.clear();
for (std::list<QString>::iterator i = current.begin();i != current.end();i++)
{
if (!dlopen(*i, RTLD_NOW | RTLD_GLOBAL))
{
failed.insert(failed.end(), *i);
}
else
{
success = true;
progress->setProgress(progress->progress() + 1);
QFileInfo file(*i);
label->setText(qApp->translate("main", "Loaded plugin %1").arg(file.fileName()));
qApp->processEvents();
}
}
}
while (failed.begin() != failed.end() && success);
for (std::list<QString>::iterator i = failed.begin();i != failed.end();i++)
if (!dlopen(*i, RTLD_NOW | RTLD_GLOBAL))
fprintf(stderr, "Failed to load %s\n %s\n",
(const char *)(*i), dlerror());
}
#endif
try
{
toSQL::loadSQL(toConfigurationSingle::Instance().sqlFile());
}
catch (...)
{}
toConnectionProvider::initializeAll();
{
QString nls = getenv("NLS_LANG");
if (nls.isEmpty())
nls = "american_america.UTF8";
else
{
int pos = nls.lastIndexOf('.');
if (pos > 0)
nls = nls.left(pos);
nls += ".UTF8";
}
toSetEnv("NLS_LANG", nls);
}
if (toConfigurationSingle::Instance().lastVersion() != TOVERSION)
{
std::auto_ptr<toAbout> about ( new toAbout(toAbout::About, NULL, "About " TOAPPNAME, true));
if (!about->exec())
{
exit (2);
}
toConfigurationSingle::Instance().setLastVersion(TOVERSION);
}
if (toConfigurationSingle::Instance().firstInstall().isEmpty())
{
toConfigurationSingle::Instance().setFirstInstall(
QDateTime::currentDateTime().toString());
}
toQValue::setNumberFormat(
toConfigurationSingle::Instance().numberFormat(),
toConfigurationSingle::Instance().numberDecimals());
if (qApp->argc() > 2 || (qApp->argc() == 2 && qApp->argv()[1][0] == '-'))
{
printf("Usage:\n\n tora [{X options}] [connectstring]\n\n");
exit(2);
}
else if (qApp->argc() == 2)
{
QString connect = QString::fromLatin1(qApp->argv()[1]);
QString user;
int pos = connect.indexOf(QString::fromLatin1("@"));
if (pos > -1)
{
user = connect.left(pos);
connect = connect.right(connect.length() - pos - 1);
}
else
{
user = connect;
if (getenv("ORACLE_SID"))
connect = QString::fromLatin1(getenv("ORACLE_SID"));
}
if (!connect.isEmpty())
toConfigurationSingle::Instance().setDefaultDatabase(connect);
pos = user.indexOf(QString::fromLatin1("/"));
if (pos > -1)
{
toConfigurationSingle::Instance().setDefaultPassword(user.right(user.length() - pos - 1));
user = user.left(pos);
}
if (!user.isEmpty())
toConfigurationSingle::Instance().setDefaultUser(user);
}
toMarkedText::setDefaultTabWidth(toConfigurationSingle::Instance().tabStop());
toMarkedText::setDefaultTabSpaces(toConfigurationSingle::Instance().tabSpaces());
// toUpdateIndicateEmpty();
new toMain;
int ret = qApp->exec();
return ret;
}
catch (const QString &str)
{
fprintf(stderr,
"Unhandled exception:\n\n%s\n",
(const char *) str.toLatin1());
TOMessageBox::critical(NULL,
qApp->translate("main", "Unhandled exception"),
str,
qApp->translate("main", "Exit"));
}
return 1;
}
|