• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
main.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2002-2013 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 // app includes
12 #include "debug_utils.h"
13 #include "uml.h"
14 #include "version.h"
15 #include "umldoc.h"
16 #include "cmdlineexportallviewsevent.h"
17 #include "umlviewimageexportermodel.h"
18 #include "umbrellosettings.h"
19 
20 // kde includes
21 #include <kaboutdata.h>
22 #include <kapplication.h>
23 #include <kcmdlineargs.h>
24 #include <kconfig.h>
25 #include <klocale.h>
26 #include <ktip.h>
27 #include <kwindowsystem.h>
28 
29 #include <unistd.h>
30 #include <stdio.h>
31 
35 static const char description[] =
36  I18N_NOOP("Umbrello UML Modeller");
37 
45 bool getShowGUI(KCmdLineArgs *args);
46 
55 void initDocument(KCmdLineArgs *args);
56 
64 void exportAllViews(KCmdLineArgs *args, const QStringList &exportOpt);
65 
66 int main(int argc, char *argv[])
67 {
68  KAboutData aboutData("umbrello", 0, ki18n("Umbrello UML Modeller"),
69  umbrelloVersion(), ki18n(description), KAboutData::License_GPL,
70  ki18n("(c) 2001 Paul Hensgen, (c) 2002-2013 Umbrello UML Modeller Authors"), KLocalizedString(),
71  "http://umbrello.kde.org/");
72  aboutData.addAuthor(ki18n("Paul Hensgen"), KLocalizedString(), "phensgen@users.sourceforge.net");
73  aboutData.addAuthor(ki18n("Umbrello UML Modeller Authors"), KLocalizedString(), "umbrello-devel@kde.org");
74  KCmdLineArgs::init(argc, argv, &aboutData);
75 
76  KCmdLineOptions options;
77  options.add("+[File]", ki18n("File to open"));
78  options.add("export <extension>", ki18n("export diagrams to extension and exit"));
79  options.add("export-formats", ki18n("list available export extensions"));
80  options.add("directory <url>", ki18n("the local directory to save the exported diagrams in"), I18N_NOOP("the directory of the file"));
81  options.add("use-folders", ki18n("keep the tree structure used to store the views in the document in the target directory"));
82  KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
83 
84  // NOTE: for deprecated net.sf.umbrello dbus service name
85  // aboutData.setOrganizationDomain("sf.net");
86  KApplication app;
87  if (app.isSessionRestored()) {
88  kRestoreMainWindows< UMLApp >();
89  } else {
90  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
91  bool showGUI = getShowGUI(args);
92 
93  UMLApp* uml = new UMLApp();
94  app.processEvents();
95 
96  if (showGUI) {
97  uml->show();
98  }
99 
100  initDocument(args);
101 
102  if (args->isSet("export-formats")) {
103  foreach(const QString& type, UMLViewImageExporterModel::supportedImageTypes())
104  fprintf(stdout, "%s\n", qPrintable(type));
105  return 0;
106  }
107  // export option
108  QStringList exportOpt = args->getOptionList("export");
109  if (exportOpt.size() > 0) {
110  exportAllViews(args, exportOpt);
111  }
112  }
113  return app.exec();
114 }
115 
116 bool getShowGUI(KCmdLineArgs *args)
117 {
118  if (args->getOptionList("export").size() > 0 || args->isSet("export-formats")) {
119  return false;
120  }
121  return true;
122 }
123 
124 void initDocument(KCmdLineArgs *args)
125 {
126  if (args->count()) {
127  UMLApp::app()->openDocumentFile(args->url(0));
128  } else {
129  bool last = UmbrelloSettings::loadlast();
130  QString file = UmbrelloSettings::lastFile();
131  if(last && !file.isEmpty()) {
132  UMLApp::app()->openDocumentFile(KUrl(file));
133  } else {
134  UMLApp::app()->newDocument();
135  }
136  }
137 }
138 
139 void exportAllViews(KCmdLineArgs *args, const QStringList &exportOpt)
140 {
141  QString extension(exportOpt.last());
142  uDebug() << "extension: " << extension;
143 
144  // export to the specified directory, or the directory where the file is saved
145  // if no directory was specified
146  KUrl directory;
147  QStringList directoryOpt = args->getOptionList("directory");
148  if (directoryOpt.size() > 0) {
149  directory = KCmdLineArgs::makeURL(directoryOpt.last().toLocal8Bit());
150  } else {
151  directory = KUrl(UMLApp::app()->document()->url().directory());
152  }
153 
154  bool useFolders = args->isSet("use-folders");
155 
156  uDebug() << "directory: " << directory.prettyUrl();
157 
158  // the event is posted so when the Qt loop begins it's processed. UMLApp process this event executing
159  // the method it provides for exporting the views. Once all the views were exported, a quit event
160  // is sent and the app finishes without user interaction
161  kapp->postEvent(UMLApp::app(), new CmdLineExportAllViewsEvent(extension, directory, useFolders));
162 }
163 
UniqueID::init
void init()
Reinitialize the unique ID counter.
Definition: uniqueid.cpp:37
umbrellosettings.h
UmbrelloSettings::lastFile
static QString lastFile()
Get lastFile.
Definition: umbrellosettings.h:324
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
UMLApp::newDocument
void newDocument()
Calls the UMLDoc method to create a new Document.
Definition: uml.cpp:2779
initDocument
void initDocument(KCmdLineArgs *args)
Initializes the document used by the application.
Definition: main.cpp:124
UMLApp::openDocumentFile
void openDocumentFile(const KUrl &url=KUrl())
Opens a file specified by commandline option.
Definition: uml.cpp:856
UMLViewImageExporterModel::supportedImageTypes
static QStringList supportedImageTypes()
Returns a QStringList containing all the supported image types to use when exporting.
Definition: umlviewimageexportermodel.cpp:56
debug_utils.h
getShowGUI
bool getShowGUI(KCmdLineArgs *args)
Determines if the application GUI should be shown based on command line arguments.
Definition: main.cpp:116
CmdLineExportAllViewsEvent
This class provides an event that is posted to the UMLApp when the "export all views" option was set ...
Definition: cmdlineexportallviewsevent.h:27
UMLApp
The base class for UML application windows.
Definition: uml.h:81
uDebug
#define uDebug()
Definition: debug_utils.h:95
exportAllViews
void exportAllViews(KCmdLineArgs *args, const QStringList &exportOpt)
Export all the views in the document using the command line args set by the user. ...
Definition: main.cpp:139
umlviewimageexportermodel.h
UmbrelloSettings::loadlast
static bool loadlast()
Get Load Last.
Definition: umbrellosettings.h:267
version.h
umldoc.h
cmdlineexportallviewsevent.h
description
static const char description[]
Description for this application.
Definition: main.cpp:35
umbrelloVersion
QByteArray umbrelloVersion()
Definition: version.h:16
main
int main(int argc, char *argv[])
Definition: main.cpp:66
uml.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:06:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal