My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
main.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  main.cpp - description
3  -------------------
4  begin : Thu Aug 28 18:17:41 CEST 2003
5  copyright : (C) 2005 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 
22 #include <stdlib.h>
23 
24 #include <qapplication.h>
25 #include <qstring.h>
26 #include <qtextcodec.h>
27 #include <qtranslator.h>
28 #include <qfile.h>
29 #include <qtextstream.h>
30 #include <qmessagebox.h>
31 #include <qdir.h>
32 #include <qfont.h>
33 
34 #include "qucsfilter.h"
35 
37 
38 // #########################################################################
39 // Loads the settings file and stores the settings.
41 {
42  bool result = true;
43 
44  QFile file(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/filterrc"));
45  if(!file.open(IO_ReadOnly))
46  result = false; // settings file doesn't exist
47  else {
48  QTextStream stream(&file);
49  QString Line, Setting;
50  while(!stream.atEnd()) {
51  Line = stream.readLine();
52  Setting = Line.section('=',0,0);
53  Line = Line.section('=',1,1);
54  if(Setting == "FilterWindow") {
55  QucsSettings.x = Line.section(",",0,0).toInt();
56  QucsSettings.y = Line.section(",",1,1).toInt();
57  break;
58  }
59  }
60  file.close();
61  }
62 
63  file.setName(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/qucsrc"));
64  if(!file.open(IO_ReadOnly))
65  result = true; // qucs settings not necessary
66  else {
67  QTextStream stream(&file);
68  QString Line, Setting;
69  while(!stream.atEnd()) {
70  Line = stream.readLine();
71  Setting = Line.section('=',0,0);
72  Line = Line.section('=',1,1).stripWhiteSpace();
73  if(Setting == "Font")
74  QucsSettings.font.fromString(Line);
75  else if(Setting == "Language")
76  QucsSettings.Language = Line;
77  }
78  file.close();
79  }
80  return result;
81 }
82 
83 // #########################################################################
84 // Saves the settings in the settings file.
86 {
87  if(qucs->x() == QucsSettings.x)
88  if(qucs->y() == QucsSettings.y)
89  return true; // nothing has changed
90 
91 
92  QFile file(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/filterrc"));
93  if(!file.open(IO_WriteOnly)) {
94  QMessageBox::warning(0, QObject::tr("Warning"),
95  QObject::tr("Cannot save settings !"));
96  return false;
97  }
98 
99  QString Line;
100  QTextStream stream(&file);
101 
102  stream << "Settings file, Qucs Filter " PACKAGE_VERSION "\n"
103  << "FilterWindow=" << qucs->x() << ',' << qucs->y() << '\n';
104 
105  file.close();
106  return true;
107 }
108 
109 
110 // #########################################################################
111 // ########## ##########
112 // ########## Program Start ##########
113 // ########## ##########
114 // #########################################################################
115 
116 int main(int argc, char *argv[])
117 {
118  // apply default settings
119  QucsSettings.x = 200;
120  QucsSettings.y = 100;
121  QucsSettings.font = QFont("Helvetica", 12);
122 
123  // is application relocated?
124  char * var = getenv ("QUCSDIR");
125  if (var != NULL) {
126  QDir QucsDir = QDir (var);
127  QString QucsDirStr = QucsDir.canonicalPath ();
129  QDir::convertSeparators (QucsDirStr + "/share/qucs/bitmaps/");
131  QDir::convertSeparators (QucsDirStr + "/share/qucs/lang/");
132  } else {
133  QucsSettings.BitmapDir = BITMAPDIR;
134  QucsSettings.LangDir = LANGUAGEDIR;
135  }
136 
137  loadSettings();
138 
139  QApplication a(argc, argv);
140  a.setFont(QucsSettings.font);
141 
142  QTranslator tor( 0 );
143  QString lang = QucsSettings.Language;
144  if(lang.isEmpty())
145  lang = QTextCodec::locale();
146  tor.load( QString("qucs_") + lang, QucsSettings.LangDir);
147  a.installTranslator( &tor );
148 
149  QucsFilter *qucs = new QucsFilter();
150  a.setMainWidget(qucs);
151  qucs->move(QucsSettings.x, QucsSettings.y); // position before "show" !!!
152  qucs->show();
153  int result = a.exec();
154  saveApplSettings(qucs);
155  return result;
156 }