umbrello API Documentation

main.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2002-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 #include <unistd.h>
00013 
00014 // kde includes
00015 #include <kaboutdata.h>
00016 #include <kapplication.h>
00017 #include <kcmdlineargs.h>
00018 #include <kconfig.h>
00019 #include <klocale.h>
00020 #include <ktip.h>
00021 #include <kdebug.h>
00022 #include <kwin.h>
00023 
00024 // app includes
00025 #include "uml.h"
00026 #include "version.h"
00027 #include "umldoc.h"
00028 #include "cmdlineexportallviewsevent.h"
00029 #include "kstartuplogo.h"
00030 
00031 static const char description[] =
00032     I18N_NOOP("Umbrello UML Modeller");
00033 // INSERT A DESCRIPTION FOR YOUR APPLICATION HERE
00034 
00038 static KCmdLineOptions options[] =
00039     {
00040         { "+[File]", I18N_NOOP("File to open"), 0 },
00041         { "export <extension>", I18N_NOOP("export diagrams to extension and exit"), 0},
00042         { "directory <url>", I18N_NOOP("the local directory to save the exported diagrams in"), I18N_NOOP("the directory of the file")},
00043         { "use-folders", I18N_NOOP("keep the tree structure used to store the views in the document in the target directory"), 0},
00044         // INSERT YOUR COMMANDLINE OPTIONS HERE
00045         KCmdLineLastOption
00046     };
00047 
00054 bool getShowGUI(KCmdLineArgs *args);
00055 
00065 KStartupLogo* showStartupLogo(KConfig* cfg, bool showGUI);
00066 
00076 void initDocument(KCmdLineArgs *args, KConfig* cfg);
00077 
00085 void exportAllViews(KCmdLineArgs *args, const QCStringList &exportOpt);
00086 
00087 extern "C" int flushEvents() {
00088     kapp->processEvents();
00089     return 0;
00090 }
00091 
00092 int main(int argc, char *argv[]) {
00093     KAboutData aboutData( "umbrello", I18N_NOOP("Umbrello UML Modeller"),
00094                           UMBRELLO_VERSION, description, KAboutData::License_GPL,
00095                           I18N_NOOP("(c) 2001 Paul Hensgen, (c) 2002-2006 Umbrello UML Modeller Authors"), 0,
00096                           "http://uml.sf.net/");
00097     aboutData.addAuthor("Paul Hensgen",0, "phensgen@users.sourceforge.net");
00098     aboutData.addAuthor(I18N_NOOP("Umbrello UML Modeller Authors"), 0, "uml-devel@lists.sourceforge.net");
00099     KCmdLineArgs::init( argc, argv, &aboutData );
00100     KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
00101 
00102     KApplication app;
00103     if( app.isRestored() ) {
00104         RESTORE( UMLApp );
00105     } else {
00106         KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00107         bool showGUI = getShowGUI(args);
00108 
00109         UMLApp *uml = new UMLApp();
00110         flushEvents();
00111         KConfig * cfg = app.config();
00112 
00113         KStartupLogo* startLogo = showStartupLogo(cfg, showGUI);
00114 
00115         if (showGUI) {
00116             uml->show();
00117         }
00118         uml->initGenerator();
00119 
00120         //show tips if wanted
00121         if (showGUI) {
00122             KTipDialog::showTip();
00123         }
00124 
00125         initDocument(args, cfg);
00126 
00127         // export option
00128         QCStringList exportOpt = args->getOptionList("export");
00129         if (exportOpt.size() > 0) {
00130              exportAllViews(args, exportOpt);
00131         }
00132 
00133         if ( showGUI && (startLogo != 0L) && !startLogo->isHidden() ) {
00134             startLogo->raise();
00135         }
00136     }
00137     return app.exec();
00138 }
00139 
00140 bool getShowGUI(KCmdLineArgs *args) {
00141     if (args->getOptionList("export").size() > 0) {
00142         return false;
00143     }
00144 
00145     return true;
00146 }
00147 
00148 KStartupLogo* showStartupLogo(KConfig* cfg, bool showGUI) {
00149     KStartupLogo* startLogo = 0L;
00150 
00151     cfg->setGroup( "General Options" );
00152     bool showLogo = cfg->readBoolEntry( "logo", true );
00153     if (showGUI && showLogo) {
00154 #if KDE_IS_VERSION(3,3,90)
00155         startLogo = new KStartupLogo(0);
00156         startLogo->setHideEnabled(true);
00157         KWin::setMainWindow(startLogo, UMLApp::app()->winId());
00158 #else
00159         startLogo = new KStartupLogo(UMLApp::app());
00160         startLogo->setHideEnabled(true);
00161 #endif
00162         KWin::setState(startLogo->winId(), NET::KeepAbove);
00163         startLogo->show();
00164         QApplication::flushX();
00165     }
00166 
00167     return startLogo;
00168 }
00169 
00170 void initDocument(KCmdLineArgs *args, KConfig* cfg) {
00171     if ( args -> count() ) {
00172         UMLApp::app()->openDocumentFile( args->url( 0 ) );
00173     } else {
00174         cfg->setGroup( "General Options" );
00175         bool last = cfg->readBoolEntry( "loadlast", false );
00176         QString file = cfg->readPathEntry( "lastFile" );
00177         if( last && !file.isEmpty() ) {
00178             UMLApp::app()->openDocumentFile( KURL( file ) );
00179         } else {
00180             UMLApp::app()->newDocument();
00181         }
00182     }
00183 }
00184 
00185 void exportAllViews(KCmdLineArgs *args, const QCStringList &exportOpt) {
00186     QString extension(exportOpt.last());
00187     kDebug() << "extension: " << extension << endl;
00188 
00189     // export to the specified directory, or the directory where the file is saved
00190     // if no directory was specified
00191     KURL directory;
00192     QCStringList directoryOpt = args->getOptionList("directory");
00193     if (directoryOpt.size() > 0) {
00194         directory = KCmdLineArgs::makeURL(directoryOpt.last());
00195     } else {
00196         directory = KURL(UMLApp::app()->getDocument()->URL().directory());
00197     }
00198 
00199     bool useFolders = args->isSet("use-folders");
00200 
00201     kDebug() << "directory: " << directory.prettyURL() << endl;
00202 
00203     // the event is posted so when the QT loop begins it's processed. UMLApp process this event executing
00204     // the method it provides for exporting the views. Once all the views were exported, a quit event
00205     // is sent and the app finishes without user interaction
00206     kapp->postEvent(UMLApp::app(), new CmdLineExportAllViewsEvent(extension, directory, useFolders));
00207 }
00208 
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:58 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003