00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qmainwindow.h>
00019 #include <qlayout.h>
00020 #include <qlabel.h>
00021 #include <qpushbutton.h>
00022 #include <qmessagebox.h>
00023 #include <qstringlist.h>
00024 #include <qfileinfo.h>
00025 #include <qfiledialog.h>
00026
00027 #include <string.h>
00028
00029 #include "RioMMSync.h"
00030
00031 QWidget *widget;
00032
00033 RioMMSync::RioMMSync( QWidget *parent, const char *name, WFlags f )
00034 : QDialog( parent, name, true, f )
00035 {
00036 widget = new QWidget( this );
00037 }
00038
00039 bool RioMMSync::Initialize( QFileInfo fiSyncFile, int type, int position )
00040 {
00041
00042 leNewLine = new QLineEdit( this, "leNewLine" );
00043 leNewLine->setFixedWidth( 400 );
00044
00045 teFileContent = new QTextEdit( this, "teFileContent" );
00046 teFileContent->setTextFormat( PlainText );
00047 teFileContent->setFixedWidth( 460 );
00048 teFileContent->setFixedHeight( 480 );
00049
00050 blockNumber = position;
00051 syncType = type;
00052
00053
00054 QPushButton *pbAddNewLine = new QPushButton( "Add", this );
00055 pbAddNewLine->setFixedWidth( 50 );
00056 pbAddNewLine->setDefault( true );
00057 QPushButton *pbOK = new QPushButton( "OK", this );
00058 pbOK->setFixedWidth( 60 );
00059 QPushButton *pbCancel = new QPushButton( "Cancel", this );
00060 pbCancel->setFixedWidth( 60 );
00061
00062
00063 setCaption( "Editing sync file" );
00064
00065
00066 QGridLayout *fileContentLayout = new QGridLayout( 2 , 1 );
00067 fileContentLayout->setSpacing( 10 );
00068 fileContentLayout->setMargin( 0 );
00069
00070 QGridLayout *newLineLayout = new QGridLayout( 1 , 2 );
00071 newLineLayout->setSpacing( 10 );
00072 newLineLayout->setMargin( 0 );
00073
00074
00075 QHBoxLayout *buttonLayout = new QHBoxLayout();
00076
00077
00078 QVBoxLayout *mainLayout = new QVBoxLayout( widget );
00079 mainLayout->setMargin( 10 );
00080 mainLayout->setSpacing( 0 );
00081
00082
00083 fileContentLayout->addWidget( new QLabel( "File content:", this ), 0, 0 );
00084 fileContentLayout->addWidget( teFileContent, 1, 0 );
00085
00086 newLineLayout->addWidget( leNewLine, 0, 0 );
00087 newLineLayout->addWidget( pbAddNewLine, 0, 1 );
00088
00089 buttonLayout->addWidget( pbOK, 0 );
00090 buttonLayout->addWidget( pbCancel, 0 );
00091
00092 mainLayout->addLayout( fileContentLayout );
00093 mainLayout->addLayout( newLineLayout );
00094 mainLayout->addLayout( buttonLayout );
00095
00096
00097 widget->setFixedSize( widget->minimumSizeHint() );
00098 setFixedSize( widget->minimumSizeHint() );
00099
00100
00101 setTabOrder( teFileContent, leNewLine );
00102 setTabOrder( leNewLine, pbAddNewLine );
00103 setTabOrder( pbAddNewLine, pbOK );
00104 setTabOrder( pbOK, pbCancel );
00105
00106
00107 connect( pbAddNewLine, SIGNAL( clicked() ),
00108 this, SLOT( addNewLine() ) );
00109 connect( pbOK, SIGNAL( clicked() ), this, SLOT( processInput() ) );
00110 connect( pbCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00111
00112 if( readSyncFile( fiSyncFile ) )
00113 return true;
00114 else
00115 return false;
00116 }
00117
00118 bool RioMMSync::readSyncFile( QFileInfo fiSyncFile )
00119 {
00120 QString sBlock;
00121 int return_value = false;
00122
00123
00124 sBlock.setNum( blockNumber );
00125 sBlock = " [" + sBlock + "] ";
00126 fSyncFile.setName( fiSyncFile.filePath() );
00127 switch( syncType )
00128 {
00129 case SYNC_NONE:
00130 if( ! fSyncFile.exists() )
00131 {
00132 teFileContent->append( "Version(1,0);\n" );
00133 return_value = true;
00134 }
00135 else
00136 {
00137 if( fSyncFile.open( IO_ReadOnly ) )
00138 {
00139 tsSyncFile = new QTextStream( &fSyncFile );
00140 while( ! tsSyncFile->atEnd() )
00141 teFileContent->append( tsSyncFile->readLine() );
00142 fSyncFile.close();
00143 return_value = true;
00144 }
00145 else
00146 QMessageBox::critical( 0, "riommclient",
00147 "Could not open file:"
00148 + fiSyncFile.fileName() );
00149 }
00150 leNewLine->setText( sBlock );
00151
00152 break;
00153
00154 case SYNC_BROWSER:
00155 if( ! fSyncFile.exists() )
00156 {
00157 teFileContent->append( "Version(1,0);\n" );
00158 teFileContent->append( "Archive(\"" + fiSyncFile.baseName()
00159 + ".zip\");\n" );
00160 return_value = true;
00161 }
00162 else
00163 {
00164 if( fSyncFile.open( IO_ReadOnly ) )
00165 {
00166 tsSyncFile = new QTextStream( &fSyncFile );
00167 while( ! tsSyncFile->atEnd() )
00168 teFileContent->append( tsSyncFile->readLine() );
00169 fSyncFile.close();
00170 return_value = true;
00171 }
00172 else
00173 QMessageBox::critical( 0, "riommclient",
00174 "Could not open file:"
00175 + fiSyncFile.fileName() );
00176 }
00177 leNewLine->setText( sBlock + "OpenURL(\"LOCAL:imgN.html\");" );
00178
00179 break;
00180
00181 case SYNC_TGIF:
00182 if( ! fSyncFile.exists() )
00183 {
00184 teFileContent->append( "Version(1,0);\n" );
00185 teFileContent->append( "Archive(\"" + fiSyncFile.baseName()
00186 + ".zip\");\n" );
00187 teFileContent->append( "[0] File(\"" + fiSyncFile.baseName()
00188 + ".obj\")\n{" );
00189 return_value = true;
00190 }
00191 else
00192 {
00193 if( fSyncFile.open( IO_ReadOnly ) )
00194 {
00195 tsSyncFile = new QTextStream( &fSyncFile );
00196 while( ! tsSyncFile->atEnd() )
00197 teFileContent->append( tsSyncFile->readLine() );
00198 fSyncFile.close();
00199 return_value = true;
00200 }
00201 else
00202 QMessageBox::critical( 0, "riommclient",
00203 "Could not open file:"
00204 + fiSyncFile.fileName() );
00205 }
00206 leNewLine->setText( sBlock + "Slide(N);" );
00207
00208 break;
00209 }
00210
00211 return return_value;
00212 }
00213
00214 bool RioMMSync::writeSyncFile( )
00215 {
00216 bool return_value = false;
00217
00218 if( fSyncFile.exists() )
00219 if( ! fSyncFile.remove() )
00220 QMessageBox::critical( 0, "riommclient",
00221 "Could not create file:"
00222 + fSyncFile.name() );
00223
00224 if( fSyncFile.open( IO_WriteOnly ) )
00225 {
00226 tsSyncFile = new QTextStream( &fSyncFile );
00227 ( *tsSyncFile ) << teFileContent->text() << endl;
00228 fSyncFile.close();
00229 return_value = true;
00230 }
00231 else
00232 QMessageBox::critical( 0, "riommclient",
00233 "Could not create file:"
00234 + fSyncFile.name() );
00235 return return_value;
00236 }
00237
00238 void RioMMSync::processInput()
00239 {
00240 if( writeSyncFile( ) )
00241 accept();
00242 }
00243
00244 void RioMMSync::addNewLine()
00245 {
00246 teFileContent->append( leNewLine->text() );
00247 }