@@ -36,7 +36,15 @@ DEALINGS IN THE SOFTWARE.
3636# include  " ./gen_conf_ed.h" 
3737# include  " ../resource.h" 
3838# include  " ./code/trstring/tr_strings.h" 
39-   
39+ 
40+ //  Function to execute a process which may modify a /cmst/config file
41+ //  in /var/lib/connman or /var/lib/connman-vpn.  It will send a finished(int) 
42+ //  signal when completed.  Exit codes:
43+ //   negative number = this function never really executed
44+ //   0 = everything completed normally
45+ //   1 = one of the DBUS calls failed to complete
46+ //   2 = the external process failed to start 
47+ //   3 = the external process returned a nonzero exit code
4048// 
4149//   Constructor  
4250GEN_Editor::GEN_Editor (QWidget* parent) : QWidget(parent)
@@ -47,12 +55,12 @@ GEN_Editor::GEN_Editor(QWidget* parent) : QWidget(parent)
4755  path.clear ();
4856  process.clear ();
4957  args.clear ();
50-   filecontents.clear ();
51-   finished  = false ;
58+   filecontents.clear ();\ 
59+   proc  = NULL ;
5260
5361  //  signals and slots
5462  connect (this , SIGNAL (readCompleted ()), this , SLOT (executeProcess ()));
55-   connect ( this ,  SIGNAL ( processCompleted ()),  this ,  SLOT ( editContents ()));  
63+   
5664  return ;
5765 }
5866
@@ -131,49 +139,65 @@ void GEN_Editor::storeContents(const QString& data)
131139}
132140
133141// 
134- //  Slot to execute the process.  This blocks untill the the process is complete or timeouts
135- //  connected to the readCompleted signal emited by storeContents
142+ //  Slot to execute the process.  
136143void  GEN_Editor::executeProcess ()
137144{
138-   QProcess*  proc = new  QProcess (this );
145+   proc = new  QProcess (this );
139146  proc->start (process, args);
140-   if  (! proc->waitForStarted () ) return ;
141- 
142-   if  (! proc->waitForFinished ()) return ;
147+   if  (! proc->waitForStarted () ) {
148+     emit finished (2 );
149+     return ;
150+   }
143151
144-   changed = QString (proc->readAll ()).split (' \n ' 
145-   emit processCompleted ();
152+   connect  (proc, SIGNAL (finished (int )), this , SLOT (processExitCode (int )));
146153
147154  return ; 
155+ 
156+ }
157+ 
158+ // 
159+ //  Slot to process the return codes from executeProcess
160+ void  GEN_Editor::processExitCode (int  exitcode)
161+ {
162+   if  (exitcode == 0 ) {
163+     changed = QString (proc->readAll ()).split (' \n ' 
164+     editBuffer ();   
165+   }
166+   else 
167+     emit  (finished (3 ));
168+ 
169+   return ;
148170}
171+  
149172
150173// 
151- //   Slot to edit the contents of the config file.  Connected to the processCompleted
152- //   signal emited by executeProcess
153- void  GEN_Editor::editContents ()
174+ //   Slot to edit the buffer containing the contents of the config file.  Connected to  processExitCode() function
175+ void  GEN_Editor::editBuffer ()
154176{
155-   if  (changed.size () <= 0  ) return ;
156- 
157-   for  (int  i = 0 ; i < filecontents.size (); ++i) {
158-     if  (filecontents.at (i).size () == 0 ) {
159-       filecontents.removeAt (i);
160-       continue ;
161-       }
162-     for  (int  j = 0 ; j < changed.size (); ++j) {
163-       if  (changed.at (j).size () == 0 ) {
164- 	changed.removeAt (j);
177+   if  (changed.size () > 0  ) {
178+     for  (int  i = 0 ; i < filecontents.size (); ++i) {
179+       if  (filecontents.at (i).size () == 0 ) {
180+ 	filecontents.removeAt (i);
165181	continue ;
166182	}
167-       if (filecontents.at (i).split (' =' at (0 ).simplified () == changed.at (j).split (' =' at (0 ).simplified ()) {
168- 	filecontents.removeAt (i);
169- 	filecontents.insert (i, changed.at (j));
170- 	changed.removeAt (j);
171-       }	//  if
172-     }//  j for
173-   } //  i for
174-   if  (changed.size () > 0 ) filecontents.append (changed);
175-   
176-   this ->writeFile ();
183+       for  (int  j = 0 ; j < changed.size (); ++j) {
184+ 	if  (changed.at (j).size () == 0 ) {
185+ 	  changed.removeAt (j);
186+ 	  continue ;
187+ 	  }
188+ 	if (filecontents.at (i).split (' =' at (0 ).simplified () == changed.at (j).split (' =' at (0 ).simplified ()) {
189+ 	  filecontents.removeAt (i);
190+ 	  filecontents.insert (i, changed.at (j));
191+ 	  changed.removeAt (j);
192+ 	}	//  if
193+       }//  j for
194+     } //  i for
195+     if  (changed.size () > 0 ) filecontents.append (changed);
196+     
197+     this ->writeFile ();
198+   } //  if we changed something
199+ 
200+   else  emit finished (0 );
177201
178202  return ;
179203}
@@ -195,9 +219,7 @@ void GEN_Editor::writeCompleted(qint64 bytes)
195219      msg = tr (" %L1 Bytes written" arg (bytes);
196220  }
197221
198-   finished = true ;
199- 
200-   qDebug () <<  msg;
222+   emit finished (0 );
201223
202224  return ;
203225}
@@ -212,7 +234,7 @@ void GEN_Editor::callbackErrorHandler(QDBusError err)
212234    QMessageBox::Ok,
213235    QMessageBox::Ok);
214236
215-   finished =  true ;
237+   emit  finished ( 1 ) ;
216238
217239  return ;
218240}
0 commit comments