• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

main.cpp

Go to the documentation of this file.
00001 #include <config.h>
00002 
00003 #include <dcopclient.h>
00004 #include <dcopref.h>
00005 #include <kapplication.h>
00006 #include <kcmdlineargs.h>
00007 #include <kdebug.h>
00008 #include <kmimetype.h>
00009 #include <kurl.h>
00010 #include <klocale.h>
00011 #include <kaboutdata.h>
00012 #include <qdir.h>
00013 
00014 #include <stdlib.h>
00015 
00016 #include "kviewshell.h"
00017 
00018 
00019 static KCmdLineOptions options[] =
00020 {
00021   { "u", 0, 0},
00022   { "unique", I18N_NOOP("Check if the file is loaded in another kviewshell.\nIf it is, bring up the other kviewshell. Otherwise, load the file."), 0 },
00023   { "m", 0, 0},
00024   { "mimetype <mimetype>", I18N_NOOP("Loads a plugin which supports files of type <mimetype>,\nif one is installed."), 0 },
00025   { "g", 0, 0},
00026   { "goto <pagenumber>", I18N_NOOP("Navigate to this page"), 0 },
00027   { "+file(s)", I18N_NOOP("Files to load"), 0 },
00028   KCmdLineLastOption
00029 };
00030 
00031 
00032 static const char description[] = I18N_NOOP("Generic framework for viewer applications");
00033 
00034 
00035 int main(int argc, char **argv)
00036 {
00037   KAboutData about ("kviewshell", I18N_NOOP("KViewShell"), "0.6",
00038             description, KAboutData::License_GPL,
00039             "(C) 2000, Matthias Hoelzer-Kluepfel\n"
00040                     "(C) 2004-2005, Wilfried Huss",
00041             I18N_NOOP("Displays various document formats. "
00042             "Based on original code from KGhostView."));
00043   about.addAuthor ("Wilfried Huss", I18N_NOOP("Current Maintainer"),
00044            "Wilfried.Huss@gmx.at");
00045   about.addAuthor ("Matthias Hoelzer-Kluepfel", I18N_NOOP("Framework"),
00046            "mhk@caldera.de");
00047   about.addAuthor ("David Sweet",
00048            I18N_NOOP("KGhostView Maintainer"),
00049            "dsweet@kde.org",
00050            "http://www.chaos.umd.edu/~dsweet");
00051   about.addAuthor ("Mark Donohoe",
00052            I18N_NOOP("KGhostView Author"));
00053   about.addAuthor ("Markku Hihnala",
00054            I18N_NOOP("Navigation widgets"));
00055   about.addAuthor ("David Faure",
00056            I18N_NOOP("Basis for shell"));
00057   about.addAuthor ("Daniel Duley",
00058            I18N_NOOP("Port to KParts"));
00059   about.addAuthor ("Espen Sand",
00060            I18N_NOOP("Dialog boxes"));
00061   about.addAuthor ("Stefan Kebekus",
00062            I18N_NOOP("DCOP-Interface, major improvements"),
00063            "kebekus@kde.org");
00064 
00065   KCmdLineArgs::init(argc, argv, &about);
00066   KCmdLineArgs::addCmdLineOptions( options ); // Add my own options.
00067   KApplication app;
00068 
00069   // see if we are starting with session management
00070   if (app.isRestored())
00071   {
00072     RESTORE(KViewShell);
00073   }
00074   else
00075   {
00076     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00077 
00078     if (args->isSet("unique")){
00079       // With --unique, we need one argument.
00080       if (args->count() < 1) {
00081         args->usage();
00082         exit(-1);
00083       }
00084 
00085       // Find the fully qualified file name of the file we are
00086       // loading. Complain, if we are given a URL which does not point
00087       // to a local file.
00088       KURL url(args->url(0));
00089 
00090       if (!args->url(0).isValid()) {
00091         kdError(1223) << QString(I18N_NOOP("The URL %1 is not well-formed.")).arg(args->arg(0)) << endl;
00092         return -1;
00093       }
00094 
00095       if (!args->url(0).isLocalFile()) {
00096         kdError(1223) << QString(I18N_NOOP("The URL %1 does not point to a local file. You can only specify local "
00097                    "files if you are using the '--unique' option.")).arg(args->arg(0)) << endl;
00098         return -1;
00099       }
00100 
00101       QString qualPath = QFileInfo(args->url(0).path()).absFilePath();
00102 
00103       app.dcopClient()->attach();
00104       QCString id = app.dcopClient()->registerAs("unique-kviewshell");
00105       if (id.isNull())
00106         kdError(1223) << "There was an error using dcopClient()->registerAs()." << endl;
00107       QCStringList apps = app.dcopClient()->registeredApplications();
00108       for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it )
00109       {
00110         if ((*it).find("kviewshell") == 0) 
00111         {
00112           QByteArray data, replyData;
00113           QCString replyType;
00114           QDataStream arg(data, IO_WriteOnly);
00115           bool result;
00116           arg << qualPath.stripWhiteSpace();
00117           if (!app.dcopClient()->call( *it, "kmultipage", "is_file_loaded(QString)", data, replyType, replyData))
00118             kdError(1223) << "There was an error using DCOP." << endl;
00119           else
00120           {
00121             QDataStream reply(replyData, IO_ReadOnly);
00122             if (replyType == "bool")
00123             {
00124               reply >> result;
00125               if (result == true)
00126               {
00127                 if (app.dcopClient()->send(*it, "kmultipage", "jumpToReference(QString)", args->url(0).ref()) == true)
00128                 {
00129                   app.dcopClient()->detach();
00130                   return 0;
00131                 }
00132               }
00133             }
00134             else
00135             {
00136               kdError(1223) << "The DCOP function 'doIt' returned an unexpected type of reply!";
00137             }
00138           }
00139         }
00140       }
00141     }
00142     app.dcopClient()->registerAs("kviewshell");
00143     KViewShell* shell;
00144 
00145     if (args->isSet("mimetype"))
00146     {
00147       shell = new KViewShell(args->getOption("mimetype"));
00148     }
00149     else if (args->count() > 0)
00150     {
00151       // If a url is given, we try to load a matching KViewShell plugin,
00152       // so we don't have to load the empty plugin first.
00153       KMimeType::Ptr mimetype = KMimeType::findByURL(args->url(0));
00154       shell = new KViewShell(mimetype->name());
00155     }
00156     else
00157     {
00158       // Load the empty plugin
00159       shell = new KViewShell();
00160     }
00161 
00162     // Show the main window before a file is loaded. This gives visual
00163     // feedback to the user and (hopefully) reduces the perceived
00164     // startup time.
00165     shell->show();
00166     app.processEvents();
00167 
00168     if ( args->count() > 0 )
00169     {
00170       KURL url = args->url(0);
00171       if (!url.hasRef() && args->isSet("goto"))
00172       {
00173         // If the url doesn't already has a reference part, add the
00174         // argument of --goto to the url as reference, to make the
00175         // KViewShell jump to this page.
00176         QString reference = args->getOption("goto");
00177         url.setHTMLRef(reference);
00178       }
00179       shell->openURL(url);
00180     }
00181   }
00182 
00183   return app.exec();
00184 }

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal