Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 498 → Rev 499

/branches/Version13x/Scribus/scribus/main.cpp
1,21 → 1,21
/***************************************************************************
main.cpp - description
-------------------
begin : Fre Apr 6 21:47:55 CEST 2001
copyright : (C) 2001 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
copyright : (C) 2004 by Alessandro Rimoldi
email : http://ideale.ch/contact
***************************************************************************/
main.cpp - description
-------------------
begin : Fre Apr 6 21:47:55 CEST 2001
copyright : (C) 2001 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
copyright : (C) 2004 by Alessandro Rimoldi
email : http://ideale.ch/contact
***************************************************************************/
 
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
 
#include <qapplication.h>
#include <qfont.h>
35,11 → 35,14
 
#include "scribus.h"
#include "langlist.h"
#include "prefsfile.h"
 
 
 
#if (_MSC_VER >= 1200)
#include "win-config.h"
#include "win-config.h"
#else
#include "config.h"
#include "config.h"
#endif
 
#define ARG_VERSION "--version"
73,81 → 76,81
 
int main(int argc, char *argv[])
{
QString arg = "";
QString arg = "";
 
arg = argv[1];
if (arg == ARG_VERSION || arg == ARG_VERSION_SHORT) {
std::cout << "Scribus Version " << VERSION << std::endl;
return 0;
} else if (arg == ARG_HELP || arg == ARG_HELP_SHORT) {
std::cout << std::endl;
std::cout << "Scribus, Open Source Desktop Publishing" << std::endl;
std::cout << "---------------------------------------" << std::endl;
std::cout << "Homepage: http://www.scribus.net " << std::endl;
std::cout << "Documentation: http://docs.scribus.net" << std::endl;
std::cout << "Issues: http://bugs.scribus.net" << std::endl;
showUsage();
return 0;
} else if (arg == ARG_AVAILLANG || arg == ARG_AVAILLANG_SHORT) {
arg = argv[1];
if (arg == ARG_VERSION || arg == ARG_VERSION_SHORT) {
std::cout << "Scribus Version " << VERSION << std::endl;
return 0;
} else if (arg == ARG_HELP || arg == ARG_HELP_SHORT) {
std::cout << std::endl;
std::cout << "Scribus, Open Source Desktop Publishing" << std::endl;
std::cout << "---------------------------------------" << std::endl;
std::cout << "Homepage: http://www.scribus.net " << std::endl;
std::cout << "Documentation: http://docs.scribus.net" << std::endl;
std::cout << "Issues: http://bugs.scribus.net" << std::endl;
showUsage();
return 0;
} else if (arg == ARG_AVAILLANG || arg == ARG_AVAILLANG_SHORT) {
showAvailLangs();
return 0;
}
}
 
for(int i = 1; i < argc; i++) {
arg = argv[i];
if ((arg == ARG_LANG || arg == ARG_LANG_SHORT) && (++i < argc)) {
lang = argv[i];
} else if (arg == ARG_NOSPLASH || arg == ARG_NOSPLASH_SHORT) {
showSplash = false;
} else if (arg == ARG_NOGUI || arg == ARG_NOGUI_SHORT) {
useGui = false;
} else if ((arg == ARG_DISPLAY || arg==ARG_DISPLAY_SHORT) && ++i < argc) {
// allow setting of display, QT expect the
// option -display <display_name>
} else {
file = QFile::decodeName(argv[i]);
if (!QFileInfo(file).exists()) {
std::cout << std::endl;
if (file.left(1) == "-" || file.left(2) == "--") {
std::cout << "Invalid argument: " << file << std::endl;
} else {
std::cout << "File " << file << "does not exist, aborting." << std::endl;
}
showUsage();
return 0;
}
}
}
for(int i = 1; i < argc; i++) {
arg = argv[i];
if ((arg == ARG_LANG || arg == ARG_LANG_SHORT) && (++i < argc)) {
lang = argv[i];
} else if (arg == ARG_NOSPLASH || arg == ARG_NOSPLASH_SHORT) {
showSplash = false;
} else if (arg == ARG_NOGUI || arg == ARG_NOGUI_SHORT) {
useGui = false;
} else if ((arg == ARG_DISPLAY || arg==ARG_DISPLAY_SHORT) && ++i < argc) {
// allow setting of display, QT expect the
// option -display <display_name>
} else {
file = QFile::decodeName(argv[i]);
if (!QFileInfo(file).exists()) {
std::cout << std::endl;
if (file.left(1) == "-" || file.left(2) == "--") {
std::cout << "Invalid argument: " << file << std::endl;
} else {
std::cout << "File " << file << "does not exist, aborting." << std::endl;
}
showUsage();
return 0;
}
}
}
 
if (useGui)
return mainGui(argc, argv);
if (useGui)
return mainGui(argc, argv);
}
 
/*!
\fn void showUsage()
\author Franz Schmid
\author Alessandro Rimoldi
\date Mon Feb 9 14:07:46 CET 2004
\brief If no argument specified the lang, returns the one in the locales
\param lang QString a two letter string describing the lang environement
\retval QString A string describing the language environement
*/
\fn void showUsage()
\author Franz Schmid
\author Alessandro Rimoldi
\date Mon Feb 9 14:07:46 CET 2004
\brief If no argument specified the lang, returns the one in the locales
\param lang QString a two letter string describing the lang environement
\retval QString A string describing the language environement
*/
 
void showUsage()
{
std::cout << std::endl;
std::cout << "Usage: scribus [option ... ] [file]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << "-l, --lang xx Uses xx as shortcut for a language" << std::endl;
std::cout << "-la, --langs-available Lists the currently installed interface languages" << std::endl;
std::cout << "-h, --help Print help (this message) and exit" << std::endl;
std::cout << "-v, --version Output version information and exit" << std::endl;
std::cout << std::endl;
std::cout << "Usage: scribus [option ... ] [file]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << "-l, --lang xx Uses xx as shortcut for a language" << std::endl;
std::cout << "-la, --langs-available Lists the currently installed interface languages" << std::endl;
std::cout << "-h, --help Print help (this message) and exit" << std::endl;
std::cout << "-v, --version Output version information and exit" << std::endl;
/*
std::cout << "-file|-- name Open file 'name'" << std::endl;
std::cout << "name Open file 'name', the file name must not begin with '-'" << std::endl;
std::cout << "QT specific options as -display ..." << std::endl;
std::cout << "-file|-- name Open file 'name'" << std::endl;
std::cout << "name Open file 'name', the file name must not begin with '-'" << std::endl;
std::cout << "QT specific options as -display ..." << std::endl;
*/
std::cout << std::endl;
std::cout << std::endl;
}
 
void showAvailLangs()
155,16 → 158,16
std::cout << "Installed Interface Languages for Scribus are as follows:" << std::endl;
std::cout << std::endl;
 
QString path = SCRIBUS_LIB;
QString path = SCRIBUS_LIB;
QString langAbbrev;
LangList langlist;
LangList::Iterator it;
 
QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
if (dir.exists() && (dir.count() != 0))
for (uint i = 0; i < dir.count(); ++i) {
QFileInfo file(path + dir[i]);
if (file.extension(false).lower() == "qm") {
QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
if (dir.exists() && (dir.count() != 0))
for (uint i = 0; i < dir.count(); ++i) {
QFileInfo file(path + dir[i]);
if (file.extension(false).lower() == "qm") {
langAbbrev = file.extension().remove(".qm");
std::cout << langAbbrev.leftJustify(6) << ": ";
if ((it=langlist.find(langAbbrev))!=langlist.end())
172,7 → 175,7
else
std::cout << "Unknown";
std::cout << std::endl;
}
}
}
 
std::cout << std::endl;
181,131 → 184,149
}
 
/*!
\fn int mainGui(int argc, char **argv)
\author Franz Schmid
\author Alessandro Rimoldi
\date Mon Feb 9 14:07:46 CET 2004
\brief Launches the Gui
\param int Number of arguments passed to Scribus
\param char *argv list of the arguments passed to Scribus
\retval int Error code from the execution of Scribus
*/
\fn int mainGui(int argc, char **argv)
\author Franz Schmid
\author Alessandro Rimoldi
\date Mon Feb 9 14:07:46 CET 2004
\brief Launches the Gui
\param int Number of arguments passed to Scribus
\param char *argv list of the arguments passed to Scribus
\retval int Error code from the execution of Scribus
*/
int mainGui(int argc, char **argv)
{
QApplication app(argc, argv);
QApplication app(argc, argv);
QStringList langs = getLang(QString(lang));
 
QStringList langs = getLang(QString(lang));
ScribusApp *scribus = new ScribusApp();
if (!langs.isEmpty())
installTranslators(&app, langs);
 
if (!langs.isEmpty())
installTranslators(&app, langs);
app.processEvents();
 
app.processEvents();
 
ScribusApp *scribus = new ScribusApp();
scribus->initGui();
if (scribus->NoFonts)
exit(EXIT_FAILURE);
scribus->initGui();
if (scribus->NoFonts)
exit(EXIT_FAILURE);
scribus->GuiLanguage = lang;
app.setMainWidget(scribus);
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
app.setMainWidget(scribus);
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
 
scribus->show();
scribus->ShowSubs();
if (file != "")
scribus->LadeDoc(file);
scribus->show();
scribus->ShowSubs();
if (file != "")
scribus->LadeDoc(file);
 
return app.exec();
return app.exec();
}
 
/*!
\fn void getLang(QString lang)
\author Franz Schmid
\author Alessandro Rimoldi
\date Mon Feb 9 14:07:46 CET 2004
\brief If the lang argument is empty, returns the value in the locales
The lang is always a two character code, except for "en_GB" where
the whole string is returned. For all the other locales starting
with "en", no locale is returned.
\fn void getLang(QString lang)
\author Franz Schmid
\author Alessandro Rimoldi
\date Mon Feb 9 14:07:46 CET 2004
\brief If the lang argument is empty, returns the value in the locales
 
(Inspired from Klocale.cpp)
The lang is always a two character code, except for "en_GB" where
the whole string is returned. For all the other locales starting
with "en", no locale is returned.
 
\param lang QString a two letter string describing the lang environement
\retval QString A string describing the language environement
*/
(Inspired from Klocale.cpp)
 
\param lang QString a two letter string describing the lang environement
\retval QString A string describing the language environement
*/
QStringList getLang(QString lang)
{
QStringList langs;
QStringList langs;
 
// read the locales
if (lang != "")
langs.push_back(lang);
#ifdef linux
if ((lang = ::getenv("LC_ALL")) != "")
langs.push_back(lang);
if ((lang = ::getenv("LC_MESSAGES")) != "")
langs.push_back(lang);
if ((lang = ::getenv("LANG")) != "")
langs.push_back(lang);
#endif
langs.push_back(QString(QTextCodec::locale()));
// read the locales
if (lang != "")
langs.push_back(lang);
//add in user preferences lang, only overridden by lang command line option
QString Pff = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus");
QString PrefsPfad;
QFileInfo Pffi = QFileInfo(Pff);
if (Pffi.exists())
{
if (Pffi.isDir())
PrefsPfad = Pff;
else
PrefsPfad = QDir::homeDirPath();
PrefsFile* prefsFile = new PrefsFile(QDir::convertSeparators(PrefsPfad + "/prefs.xml"));
if (prefsFile) {
PrefsContext* userprefsContext = prefsFile->getContext("user_preferences");
if (userprefsContext) {
QString prefslang = userprefsContext->get("gui_language","");
if (prefslang!="")
langs.push_back(prefslang);
}
}
}
#ifdef linux
if ((lang = ::getenv("LC_ALL")) != "")
langs.push_back(lang);
if ((lang = ::getenv("LC_MESSAGES")) != "")
langs.push_back(lang);
if ((lang = ::getenv("LANG")) != "")
langs.push_back(lang);
#endif
langs.push_back(QString(QTextCodec::locale()));
 
// remove duplicate entries...
for (QStringList::Iterator it = langs.fromLast(); it != langs.begin(); --it)
if (langs.contains(*it) > 1)
it = langs.remove(it);
// remove duplicate entries...
for (QStringList::Iterator it = langs.fromLast(); it != langs.begin(); --it)
if (langs.contains(*it) > 1)
it = langs.remove(it);
 
 
return langs;
return langs;
}
 
/*!
\fn void installTranslators(QApplication *app, QStringList langs)
\author Franz Schmid
\author Alessandro Rimoldi
\date Mon Feb 9 14:07:46 CET 2004
\brief Loads the translations for Scribus and for the Plugins
\param app QApplication pointer to the application object
\param lang QString a two letter string describing the lang environement
\retval void
*/
\fn void installTranslators(QApplication *app, QStringList langs)
\author Franz Schmid
\author Alessandro Rimoldi
\date Mon Feb 9 14:07:46 CET 2004
\brief Loads the translations for Scribus and for the Plugins
\param app QApplication pointer to the application object
\param lang QString a two letter string describing the lang environement
\retval void
*/
void installTranslators(QApplication *app, QStringList langs)
{
QTranslator *trans = new QTranslator(0);
QTranslator *trans= new QTranslator(0);
QString path = SCRIBUS_LIB;
path += BASE_QM;
 
QString path = SCRIBUS_LIB;
path += BASE_QM;
bool loaded = false;
for (QStringList::Iterator it = langs.begin(); it != langs.end() && !loaded; ++it) {
if ((*it).left(5) == "en_GB")
lang = "en_GB";
else
lang = (*it).left(2);
 
bool loaded = false;
for (QStringList::Iterator it = langs.begin(); it != langs.end() && !loaded; ++it) {
if ((*it).left(5) == "en_GB")
lang = "en_GB";
else
lang = (*it).left(2);
if (lang == "en")
break;
else if (loaded = trans->load(QString(path + '.' + lang), "."))
loaded = true;
}
 
if (lang == "en")
break;
else if (loaded = trans->load(QString(path + '.' + lang), "."))
loaded = true;
}
if (loaded)
app->installTranslator(trans);
 
if (loaded)
app->installTranslator(trans);
 
 
path = SCRIBUS_PLUGIN;
QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
if (dir.exists() && (dir.count() != 0)) {
for (uint i = 0; i < dir.count(); ++i) {
QFileInfo file(path + dir[i]);
if ((file.extension(false).lower() == "qm")
&& (file.extension(true).lower().left(2) == lang)) {
trans = new QTranslator(0);
trans->load(QString(path + dir[i]), ".");
app->installTranslator(trans);
}
 
}
}
path = SCRIBUS_PLUGIN;
QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
if (dir.exists() && (dir.count() != 0)) {
for (uint i = 0; i < dir.count(); ++i) {
QFileInfo file(path + dir[i]);
if ((file.extension(false).lower() == "qm")
&& (file.extension(true).lower().left(2) == lang)) {
trans = new QTranslator(0);
trans->load(QString(path + dir[i]), ".");
app->installTranslator(trans);
}
}
}
}