qucs_s/qucs-filter/main.cpp
Guilherme Brondani Torri 6dac2023c7 Done porting qucs-filter to Qt4
Compiled without Qt3Support.
2013-05-30 18:22:26 +02:00

157 lines
4.8 KiB
C++

/***************************************************************************
main.cpp - description
-------------------
begin : Thu Aug 28 18:17:41 CEST 2003
copyright : (C) 2005 by Michael Margraf
email : michael.margraf@alumni.tu-berlin.de
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <QApplication>
#include <QString>
#include <QTextCodec>
#include <QTranslator>
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <QDir>
#include <QFont>
#include "qucsfilter.h"
struct tQucsSettings QucsSettings;
// #########################################################################
// Loads the settings file and stores the settings.
bool loadSettings()
{
bool result = true;
QFile file(QDir::homePath()+QDir::convertSeparators ("/.qucs/filterrc"));
if(!file.open(QIODevice::ReadOnly))
result = false; // settings file doesn't exist
else {
QTextStream stream(&file);
QString Line, Setting;
while(!stream.atEnd()) {
Line = stream.readLine();
Setting = Line.section('=',0,0);
Line = Line.section('=',1,1);
if(Setting == "FilterWindow") {
QucsSettings.x = Line.section(",",0,0).toInt();
QucsSettings.y = Line.section(",",1,1).toInt();
break;
}
}
file.close();
}
file.setFileName(QDir::homePath()+QDir::convertSeparators ("/.qucs/qucsrc"));
if(!file.open(QIODevice::ReadOnly))
result = true; // qucs settings not necessary
else {
QTextStream stream(&file);
QString Line, Setting;
while(!stream.atEnd()) {
Line = stream.readLine();
Setting = Line.section('=',0,0);
Line = Line.section('=',1,1).trimmed();
if(Setting == "Font")
QucsSettings.font.fromString(Line);
else if(Setting == "Language")
QucsSettings.Language = Line;
}
file.close();
}
return result;
}
// #########################################################################
// Saves the settings in the settings file.
bool saveApplSettings(QucsFilter *qucs)
{
if(qucs->x() == QucsSettings.x)
if(qucs->y() == QucsSettings.y)
return true; // nothing has changed
QFile file(QDir::homePath()+QDir::convertSeparators ("/.qucs/filterrc"));
if(!file.open(QIODevice::WriteOnly)) {
QMessageBox::warning(0, QObject::tr("Warning"),
QObject::tr("Cannot save settings !"));
return false;
}
QString Line;
QTextStream stream(&file);
stream << "Settings file, Qucs Filter " PACKAGE_VERSION "\n"
<< "FilterWindow=" << qucs->x() << ',' << qucs->y() << '\n';
file.close();
return true;
}
// #########################################################################
// ########## ##########
// ########## Program Start ##########
// ########## ##########
// #########################################################################
int main(int argc, char *argv[])
{
// apply default settings
QucsSettings.x = 200;
QucsSettings.y = 100;
QucsSettings.font = QFont("Helvetica", 12);
// is application relocated?
char * var = getenv ("QUCSDIR");
if (var != NULL) {
QDir QucsDir = QDir (var);
QString QucsDirStr = QucsDir.canonicalPath ();
QucsSettings.BitmapDir =
QDir::convertSeparators (QucsDirStr + "/share/qucs/bitmaps/");
QucsSettings.LangDir =
QDir::convertSeparators (QucsDirStr + "/share/qucs/lang/");
} else {
QucsSettings.BitmapDir = BITMAPDIR;
QucsSettings.LangDir = LANGUAGEDIR;
}
loadSettings();
QApplication a(argc, argv);
a.setFont(QucsSettings.font);
QTranslator tor( 0 );
QString lang = QucsSettings.Language;
if(lang.isEmpty())
lang = QString(QLocale::system().name());
tor.load( QString("qucs_") + lang, QucsSettings.LangDir);
a.installTranslator( &tor );
QucsFilter *qucs = new QucsFilter();
qucs->raise();
qucs->move(QucsSettings.x, QucsSettings.y); // position before "show" !!!
qucs->show();
int result = a.exec();
saveApplSettings(qucs);
return result;
}