Exemplo n.º 1
0
void UmlPackage::fileControl(bool ci) {
  UmlPackage * prj = getProject();
  Q3CString prjfile = prj->supportFile();
  BooL rec;
  BooL reload;
  Q3CString cmd;
  
  if (! prj->propertyValue((ci) ? "check-in-cmd" : "check-out-cmd", cmd))
    cmd = "specify the command containing %file and %dir or %dironly";
  
  Dialog dialog(ci, cmd, rec, reload);	// the dialog execution set 'cmd' and 'rec'
  
  if (dialog.exec() == QDialog::Accepted) {
    // save the command for a future usage
    prj->set_PropertyValue((ci) ? "check-in-cmd" : "check-out-cmd", cmd);
    
    if (reload)
      saveProject();
    
    // get files list
    Q3Dict<void> files;
  
    getFiles(files, (rec) ? ~0u : 1);
    if (this == prj)
      getAuxFiles(files);
  
    // apply the command on each file
    Q3DictIterator<void> it(files);
    QFileInfo prjpath(prjfile);
    QString dir = prjpath.dirPath(TRUE);
    QString dironly = dir;
    int index;
    
    if ((dironly.length() > 3) &&
        (((const char *) dironly)[1] == ':') &&
        (((const char *) dironly)[2] == '/'))
      dironly = dironly.mid(2);
  
    while ((index = cmd.find("%dironly")) != -1)
      cmd.replace(index, 8, dironly);
    
    while ((index = cmd.find("%dir")) != -1)
      cmd.replace(index, 4, dir);
      
    while (it.current()) {
      QString s = cmd;
  
      while ((index = s.find("%file")) != -1)
        s.replace(index, 5, it.currentKey());
      
      system((const char *) s);
      ++it;
    }
    
    UmlCom::trace("Done.");
  
    if (reload)
      loadProject(prjfile);
  }
}
Exemplo n.º 2
0
int main(int argc, char ** argv)
{
  if (argc != 2)
      return 0;
  
  if (UmlCom::connect(Q3CString(argv[1]).toUInt())) {
    bool aborted = TRUE;
    
    try {
      UmlCom::trace("<b>C++ roundtrip</b> release 1.3<br>");
      UmlCom::traceAutoRaise(FALSE);
      
      char * argv = 0;
      int argc = 0;
      QApplication * app = new QApplication(argc, &argv);
      UmlItem * item = UmlCom::targetItem();
      int n;

      switch (item->kind()) {
      default:
	UmlCom::trace("<font face=helvetica><b>must be applied on a <i>package, class view, deployment view, artifact</i> or <i>class</i></b></font><br>");
	aborted = FALSE;
	throw 0;
      case aPackage:
	n = ((UmlPackage *) item)->count_roundtriped();
	break;
      case aClassView:
      case aDeploymentView:
      case anArtifact:
	n = 1;
	break;
      case aClass:
	if (item->parent()->kind() != aClassView) {
	  UmlCom::trace("<font face=helvetica><b>can't be applied on a <i>class</i> nested or out of a <i>class view</i></b></font><br>");
	  aborted = FALSE;
	  throw 0;
	}
	n = 1;
	break;
      }

      UmlPackage * project = UmlPackage::getProject();
      
      UmlCom::trace("<font face=helvetica>Upload project ...</font>");
      Package::init(project, app);
      UmlCom::trace("<font face=helvetica>...done</font><br>");
      UmlCom::message("");
      Package::set_step(0, n);
      
      UmlCom::trace("<font face=helvetica>Preparation...</font>");
      if (!item->set_roundtrip_expected() &&
	  (QMessageBox::warning(0, "Roundtrip",
				"Some elements to roundtrip are read-only and will not be updated\n\n"
				"Roundtrip anyway ?",
				"Yes", "No", QString::null, 1, 1)
	   != 0)) {
	aborted = FALSE;
	throw 0;
      }
      
      Package::set_step(0, -1);
      UmlCom::trace("<font face=helvetica>...done</font><br>");
      
      if ((item->kind() == aPackage) && !UmlArtifact::is_roundtrip_usefull()) {
	UmlCom::trace("<font face=helvetica>you don't ask for to roundtrip artifact(s)<br><br>"
		      "probably you want to do a <i>reverse</i> rather than a <i>roundtrip</i></font><br>");
	aborted = FALSE;
	throw 0;
      }
	
      Q3CString f;
	
      if (project->propertyValue("#file", f))
	Lex::defines(f);
	         
      n = 0;
      item->scan_it(n);
      CppSettings::set_UseDefaults(TRUE);
      project->set_childrenVisible(FALSE);
      item->send_it(n);
      UmlOperation::force_defs();
      Statistic::produce();
      
      // umark all
      {
	Q3PtrVector<UmlItem> marked = UmlItem::markedItems();
	UmlItem ** v = marked.data();
	UmlItem ** const vsup = v + marked.size();
	
	for (;v != vsup; v += 1)
	  (*v)->set_isMarked(FALSE);
      }
      
      Q3PtrList<UmlItem> useless;
      
      item->mark_useless(useless);
      
      if (!useless.isEmpty() &&
	  (QMessageBox::warning(0, "C++ roundtrip",
				"The marked elements are useless because they don't\n"
				"correspond to something in the roundtriped files\n\n\n"
				"Delete them ?",
				"Yes", "No", QString::null, 1, 1)
	   == 0)) {
	Q3PtrListIterator<UmlItem> iter(useless);
	
	do {
	  if (iter.current()->isMarked())
	    iter.current()->deleteIt();
	} while (++iter, iter.current() != 0);
      }
      
      project->set_childrenVisible(TRUE);
      item->set_childrenVisible(TRUE); // re select it
      aborted = FALSE;
    }
    catch (...) {
    }
    
    try {
      // socket may be already closed
      if (aborted)
	UmlCom::trace("<font face=helvetica><br><b>Rountrip aborted!</b></font><br>");	
      
      UmlCom::message("");
      UmlCom::showTrace();
      UmlCom::bye((aborted) ? 1 : 0);	// application must not be deleted
    }
    catch (...) {
    }
  }
  
  UmlCom::close();	// application must not be deleted
  return 0;
}
Exemplo n.º 3
0
void UmlPackage::fileControl(bool ci)
{
    UmlPackage * prj = getProject();
    QByteArray prjfile = prj->supportFile();
    BooL rec;
    BooL reload;
    QByteArray cmd;

    if (! prj->propertyValue((ci) ? "check-in-cmd" : "check-out-cmd", cmd))
        cmd = "specify the command containing %file and %dir or %dironly";

    Dialog dialog(ci, cmd, rec, reload);	// the dialog execution set 'cmd' and 'rec'

    if (dialog.exec() == QDialog::Accepted) {
        // save the command for a future usage
        prj->set_PropertyValue((ci) ? "check-in-cmd" : "check-out-cmd", cmd);

        if (reload)
            saveProject();

        // get files list
        QHash<QString,void*> files;

        getFiles(files, (rec) ? ~0u : 1);

        if (this == prj)
            getAuxFiles(files);

        // apply the command on each file
        QHashIterator<QString,void*> it(files);
        QFileInfo prjpath(prjfile);
        QString dir = prjpath.path();
        QString dironly = dir;
        int index;

        if ((dironly.length() > 3) &&
            (dironly[1] == ':') &&
            (dironly[2] == '/'))
            dironly = dironly.mid(2);

        while ((index = cmd.indexOf("%dironly")) != -1)
            cmd.replace(index, 8, dironly.toLatin1());

        while ((index = cmd.indexOf("%dir")) != -1)
            cmd.replace(index, 4, dir.toLatin1());

        while (it.hasNext()) {
            it.next();
            QString s = cmd;

            while ((index = s.indexOf("%file")) != -1)
                s.replace(index, 5, it.key().toLatin1());

            system((const char *) s.toLatin1().constData());
            //++it;
        }

        UmlCom::trace("Done.");

        if (reload)
            loadProject(prjfile);
    }
}