00001 #include "main.h"
00002 #include "mainwindow.h"
00003 #include "appconfig.h"
00004 #include "clipbrecords.h"
00005
00006
00007 appconfig mytetraconfig;
00008
00009
00010 QObject *mainwindowpointer;
00011
00012 void logprint(char *lpszText, ...)
00013 {
00014 va_list argList;
00015 FILE *pFile;
00016
00017
00018 va_start(argList, lpszText);
00019
00020
00021 if((pFile = fopen("mytetralog.txt", "a+")) == NULL)
00022 {
00023 printf("\nLog file not writable\n");
00024 return;
00025 }
00026
00027
00028 vfprintf(pFile, lpszText, argList);
00029
00030
00031
00032 vprintf(lpszText, argList);
00033
00034
00035 fclose(pFile);
00036 va_end(argList);
00037
00038
00039 return;
00040 }
00041
00042 void critical_error(QString message)
00043 {
00044 qDebug() << "Error!";
00045 qDebug() << message;
00046 exit(1);
00047 }
00048
00049
00050 void info_window(QString i)
00051 {
00052 QTextEdit *textarea=new QTextEdit;
00053 textarea->setPlainText(i);
00054
00055 QPushButton *closebutton=new QPushButton;
00056 closebutton->setText(QObject::tr("Close"));
00057 closebutton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00058
00059 QVBoxLayout *assemblylayout=new QVBoxLayout;
00060 assemblylayout->addWidget(textarea);
00061 assemblylayout->addWidget(closebutton,0,Qt::AlignRight);
00062
00063 QWidget *win=new QWidget;
00064 win->setLayout(assemblylayout);
00065 win->setWindowModality(Qt::ApplicationModal);
00066
00067 QObject::connect(closebutton,SIGNAL(clicked()),win,SLOT(close ()));
00068
00069 win->show();
00070 }
00071
00072
00073 QString xmlnode_to_string(QDomNode xmldata)
00074 {
00075
00076 if(xmldata.isDocument())
00077 {
00078
00079
00080 return xmldata.toDocument().toString();
00081 }
00082 else
00083 {
00084
00085
00086 QDomDocument tempdoc;
00087
00088
00089
00090
00091 QDomElement tempelm = tempdoc.createElement("stub");
00092
00093
00094 if(!xmldata.isNull())
00095 {
00096
00097 tempdoc.appendChild(xmldata.cloneNode());
00098
00099
00100 return tempdoc.toString();
00101 }
00102 else return "";
00103 }
00104 }
00105
00106
00107 QString convert_to_lastnumformat(int n)
00108 {
00109
00110 QString line;
00111 line.setNum(n);
00112
00113 qDebug() << "In convert_to_lastnotenum_line() 1 n " << n << " line " << line;
00114
00115
00116 QString t=line.rightJustified(10, '0');
00117
00118 qDebug() << "In convert_to_lastnotenum_line() 2 line " << line << " t " << t;
00119
00120 return t;
00121 }
00122
00123
00124
00125 void remove_dir(QString namedirfrom)
00126 {
00127 QDir dirfrom(namedirfrom);
00128 QStringList filelist=dirfrom.entryList();
00129
00130 QString namedirto=mytetraconfig.get_trashdir();
00131
00132
00133 for(int i=0;i<filelist.size();i++)
00134 {
00135
00136 if(filelist.at(i)=="." || filelist.at(i)=="..")continue;
00137
00138 QString filenamefrom=namedirfrom+"/"+filelist.at(i);
00139 QString filenameto =namedirto+"/"+mytetraconfig.get_lastprefixnum_as_line()+"_"+filelist.at(i);
00140 mytetraconfig.inc_lastprefixnum();
00141
00142 qDebug() << "Move file from " << filenamefrom << " to " << filenameto;
00143
00144
00145 QFile::rename(filenamefrom,filenameto);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 QDir applicationdir(QCoreApplication::applicationDirPath());
00158 qDebug() << "Try delete directory " << namedirfrom;
00159 if(!applicationdir.rmdir(namedirfrom))
00160 qDebug() << "Directory " << namedirfrom << " NOT deleted";
00161 else
00162 qDebug() << "Directory " << namedirfrom << " delete succesfull";
00163 }
00164
00165
00166
00167 char* fromQStringToChar( const QString& str )
00168 {
00169 char *tmpC=new char [str.size() + 1];
00170 QVariant var;
00171
00172 for(int i=0;i<str.length();i++)
00173 {
00174 var=str.at(i);
00175 tmpC[i] = var.toChar().toAscii();
00176 }
00177
00178 tmpC[str.size()] = 0;
00179
00180 return tmpC;
00181 }
00182
00183
00184
00185 void print_object_tree_recurse(QObject *pobj)
00186 {
00187 static int indent=0;
00188
00189 QObjectList olist;
00190
00191 olist=pobj->children();
00192
00193 for(int i=0;i<olist.size();++i)
00194 {
00195 QObject *currobj;
00196 currobj=olist.at(i);
00197
00198 QString indentline=".";
00199 for(int j=0;j<indent;j++)indentline=indentline+".";
00200
00201 if((currobj->objectName()).length()==0)
00202 qDebug("%s%s",fromQStringToChar(indentline), currobj->metaObject()->className() );
00203 else
00204 qDebug("%s%s, NAME %s",fromQStringToChar(indentline), currobj->metaObject()->className(), fromQStringToChar(currobj->objectName()) );
00205
00206 indent++;
00207 print_object_tree_recurse(currobj);
00208 indent--;
00209 }
00210 }
00211
00212
00213
00214 void print_object_tree(void)
00215 {
00216 qDebug() << "Object tree";
00217
00218 print_object_tree_recurse(mainwindowpointer);
00219 }
00220
00221
00222
00223 bool compare_QStringList_len(const QStringList &list1, const QStringList &list2)
00224 {
00225 return list1.size() < list2.size();
00226 }
00227
00228
00229 int imax(int x1, int x2)
00230 {
00231 if(x1>x2)return x1;
00232 else return x2;
00233 }
00234
00235
00236 int imin(int x1, int x2)
00237 {
00238 if(x1<x2)return x1;
00239 else return x2;
00240 }
00241
00242
00243 int main(int argc, char ** argv)
00244 {
00245 DPF(("\n\rStart MyTetra v.%d.%d\n\r",GAME_RELEASE_VERSION,GAME_RELEASE));
00246
00247 Q_INIT_RESOURCE(mytetra);
00248
00249 QApplication app(argc, argv);
00250 mainwindow win;
00251 win.setObjectName("mainwindow");
00252 mainwindowpointer=&win;
00253
00254
00255
00256
00257 win.restore_findonbase_visible();
00258 win.restore_geometry();
00259 win.restore_tree_position();
00260 win.restore_recordtable_position();
00261
00262
00263 qDebug() << "Restore session succesfull";
00264
00265
00266 print_object_tree();
00267
00268
00269 if(!QSystemTrayIcon::isSystemTrayAvailable()) {
00270 QMessageBox::critical(0, QObject::tr("Systray"),
00271 QObject::tr("I couldn't detect any system tray on this system."));
00272 exit(1);
00273 }
00274
00275
00276
00277 QApplication::setQuitOnLastWindowClosed(false);
00278
00279 win.show();
00280 app.connect(&app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
00281 return app.exec();
00282 }