compile
[kdegraphics.git] / okular / shell / main.cpp
blob635827d9e571efdebd3adc8f8753b0a63d4ccf88
1 /***************************************************************************
2 * Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
3 * Copyright (C) 2003 by Christophe Devriese *
4 * <Christophe.Devriese@student.kuleuven.ac.be> *
5 * Copyright (C) 2003 by Laurent Montel <montel@kde.org> *
6 * Copyright (C) 2003-2007 by Albert Astals Cid <aacid@kde.org> *
7 * Copyright (C) 2004 by Andy Goossens <andygoossens@telenet.be> *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 ***************************************************************************/
15 #include "shell.h"
16 #include <kapplication.h>
17 #include <kcmdlineargs.h>
18 #include <klocale.h>
19 #include <QtDBus/qdbusinterface.h>
20 #include "aboutdata.h"
22 static bool attachUniqueInstance(KCmdLineArgs* args)
24 if (!args->isSet("unique") || args->count() != 1)
25 return false;
27 QDBusInterface iface("org.kde.okular", "/okular", "org.kde.okular");
28 if (!iface.isValid())
29 return false;
31 iface.call("openDocument", args->url(0).pathOrUrl());
33 return true;
36 int main(int argc, char** argv)
38 KAboutData about = okularAboutData( "okular", I18N_NOOP( "Okular" ) );
40 KCmdLineArgs::init(argc, argv, &about);
42 KCmdLineOptions options;
43 options.add("p");
44 options.add("page <number>", ki18n("Page of the document to be shown"));
45 options.add("presentation", ki18n("Start the document in presentation mode"));
46 options.add("unique", ki18n("\"Unique session\" control"));
47 options.add("+[URL]", ki18n("Document to open"));
48 KCmdLineArgs::addCmdLineOptions( options );
49 KApplication app;
51 // see if we are starting with session management
52 if (app.isSessionRestored())
54 RESTORE(Shell);
55 } else {
56 // no session.. just start up normally
57 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
59 // try to attach the "unique" session: if we succeed, do nothing more and exit
60 if (attachUniqueInstance(args))
62 args->clear();
63 return 0;
66 if (args->count() == 0)
68 Shell* widget = new Shell(args);
69 widget->show();
71 else
73 for (int i = 0; i < args->count(); ++i)
75 Shell* widget = new Shell(args, args->url(i));
76 widget->show();
81 return app.exec();
84 // vim:ts=2:sw=2:tw=78:et