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 ** Qucs Attenuator Synthesis
3 ** main.cpp
4 **
5 **
6 **
7 **
8 **
9 **
10 **
11 *****************************************************************************/
12 
13 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16 
17 #include <stdlib.h>
18 
19 #include <qapplication.h>
20 #include <qstring.h>
21 #include <qtextcodec.h>
22 #include <qtranslator.h>
23 #include <qfile.h>
24 #include <qtextstream.h>
25 #include <qmessagebox.h>
26 #include <qdir.h>
27 #include <qfont.h>
28 
29 
30 #include "qucsattenuator.h"
31 
33 
34 
35 // #########################################################################
36 // Loads the settings file and stores the settings.
38 {
39  bool result = true;
40 
41  QFile file(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/attenuatorrc"));
42  if(!file.open(IO_ReadOnly))
43  result = false; // settings file doesn't exist
44  else {
45  QTextStream stream(&file);
46  QString Line, Setting;
47  while(!stream.atEnd()) {
48  Line = stream.readLine();
49  Setting = Line.section('=',0,0);
50  Line = Line.section('=',1,1);
51  if(Setting == "AttenuatorWindow") {
52  QucsSettings.x = Line.section(",",0,0).toInt();
53  QucsSettings.y = Line.section(",",1,1).toInt();
54  break;
55  }
56  }
57  file.close();
58  }
59 
60  file.setName(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/qucsrc"));
61  if(!file.open(IO_ReadOnly))
62  result = true; // qucs settings not necessary
63  else {
64  QTextStream stream(&file);
65  QString Line, Setting;
66  while(!stream.atEnd()) {
67  Line = stream.readLine();
68  Setting = Line.section('=',0,0);
69  Line = Line.section('=',1,1).stripWhiteSpace();
70  if(Setting == "Font")
71  QucsSettings.font.fromString(Line);
72  else if(Setting == "Language")
73  QucsSettings.Language = Line;
74  }
75  file.close();
76  }
77  return result;
78 }
79 
80 // #########################################################################
81 // Saves the settings in the settings file.
83 {
84  if(qucs->x() == QucsSettings.x)
85  if(qucs->y() == QucsSettings.y)
86  return true; // nothing has changed
87 
88 
89  QFile file(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs/attenuatorrc"));
90  if(!file.open(IO_WriteOnly)) {
91  QMessageBox::warning(0, QObject::tr("Warning"),
92  QObject::tr("Cannot save settings !"));
93  return false;
94  }
95 
96  QString Line;
97  QTextStream stream(&file);
98 
99  stream << "Settings file, Qucs Attenuator " PACKAGE_VERSION "\n"
100  << "AttenuatorWindow=" << qucs->x() << ',' << qucs->y() << '\n';
101 
102  file.close();
103  return true;
104 }
105 
106 
107 
108 int main( int argc, char ** argv )
109 {
110  // apply default settings
111  QucsSettings.x = 200;
112  QucsSettings.y = 100;
113  QucsSettings.font = QFont("Helvetica", 12);
114 
115  // is application relocated?
116  char * var = getenv ("QUCSDIR");
117  if (var != NULL) {
118  QDir QucsDir = QDir (var);
119  QString QucsDirStr = QucsDir.canonicalPath ();
121  QDir::convertSeparators (QucsDirStr + "/share/qucs/bitmaps/");
123  QDir::convertSeparators (QucsDirStr + "/share/qucs/lang/");
124  } else {
125  QucsSettings.BitmapDir = BITMAPDIR;
126  QucsSettings.LangDir = LANGUAGEDIR;
127  }
128 
129  loadSettings();
130 
131  QApplication a( argc, argv );
132  a.setFont(QucsSettings.font);
133  QTranslator tor( 0 );
134  QString lang = QucsSettings.Language;
135  if(lang.isEmpty())
136  lang = QTextCodec::locale();
137  tor.load( QString("qucs_") + lang, QucsSettings.LangDir);
138  a.installTranslator( &tor );
139 
140  QucsAttenuator *qucs = new QucsAttenuator();
141  a.setMainWidget(qucs);
142  qucs->move(QucsSettings.x, QucsSettings.y); // position before "show" !!!
143  qucs->show();
144  int result = a.exec();
145  saveApplSettings(qucs);
146  return result;
147 
148  // QApplication a( argc, argv );
149  // QucsAttenuator w;
150  // w.show();
151  // a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
152  // return a.exec();
153 }