Ejemplo n.º 1
0
int main(int argc, char **argv)
{
  KAboutData aboutData( "ksnapshot", I18N_NOOP("KSnapshot"),
    KSNAPVERSION, description, KAboutData::License_GPL,
    "(c) 1997-2004, Richard J. Moore,\n(c) 2000, Matthias Ettrich,\n(c) 2002-2003 Aaron J. Seigo");
  aboutData.addAuthor("Richard J. Moore",0, "*****@*****.**");
  aboutData.addAuthor("Matthias Ettrich",0, "*****@*****.**");
  aboutData.addAuthor("Aaron J. Seigo", 0, "*****@*****.**");
  aboutData.addCredit( "Nadeem Hasan", I18N_NOOP("Region Grabbing\nReworked GUI"),
      "*****@*****.**" );

  KCmdLineArgs::init( argc, argv, &aboutData );
  KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

  KApplication app;

  KImageIO::registerFormats();

  // Create top level window
  KSnapshot *toplevel;

  if ( args->isSet( "current" ) )
     toplevel = new KSnapshot( 0, 0, true );
  else
     toplevel = new KSnapshot();

  args->clear();
  app.dcopClient()->setDefaultObject( toplevel->objId() );
  toplevel->setCaption( app.makeStdCaption("") );
  app.setMainWidget(toplevel);
  toplevel->show();
  return app.exec();
}
Ejemplo n.º 2
0
// TODO - make this register() or something like that and move dialog into main
static int askUser(KApplication &app, QString filename, bool &readonly)
{
    QCString requestedName("keditbookmarks");

    if(!filename.isEmpty())
        requestedName += "-" + filename.utf8();

    if(app.dcopClient()->registerAs(requestedName, false) == requestedName)
        return true;

    int ret = KMessageBox::warningYesNo(0, i18n("Another instance of %1 is already running, do you really "
                                                "want to open another instance or continue work in the same instance?\n"
                                                "Please note that, unfortunately, duplicate views are read-only.")
                                               .arg(kapp->caption()),
                                        i18n("Warning"), i18n("Run Another"), /* yes */
                                        i18n("Continue in Same") /*  no */);

    if(ret == KMessageBox::No)
    {
        continueInWindow(requestedName);
        return false;
    }
    else if(ret == KMessageBox::Yes)
    {
        readonly = true;
    }

    return true;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    if(argc > 1)
    {
        batch();
        return 0;
    }
    KCmdLineArgs::init(argc, argv, "TestApp", "Tests the dcop familly of tools + libraries", "1.0"); // FIXME
    KApplication app;
    if(!app.dcopClient()->attach())
        return 1;

    app.dcopClient()->registerAs("TestApp");
    new Test;
    return app.exec();
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
  KLocale::setMainCatalogue("kmailcvt");

  KAboutData aboutData( "kmailcvt", I18N_NOOP("KMailCVT"),
    "3", I18N_NOOP("KMail Import Filters"), KAboutData::License_GPL_V2,
    I18N_NOOP("(c) 2000-2005, The KMailCVT developers"));
  aboutData.addAuthor("Hans Dijkema",I18N_NOOP("Original author"), "*****@*****.**");
  aboutData.addAuthor("Danny Kukawka", I18N_NOOP("Maintainer & New filters"), "*****@*****.**");
  aboutData.addAuthor("Laurence Anderson", I18N_NOOP("New GUI & cleanups"), "*****@*****.**");
  aboutData.addCredit("Daniel Molkentin", I18N_NOOP("New GUI & cleanups"), "*****@*****.**");

  KCmdLineArgs::init( argc, argv, &aboutData );
  KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.

  KApplication a;
  KMailCVT *kmailcvt = new KMailCVT();
  a.setMainWidget(kmailcvt);
  kmailcvt->show();  

  DCOPClient *client=a.dcopClient();
  if (!client->attach()) {
    return 1;
  }

  return a.exec();
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{

    KAboutData aboutData( "kimagemapeditor", I18N_NOOP("KImageMapEditor"),
                          VERSION, description, KAboutData::License_GPL,
                          "(C) 2001-2008 Jan Schaefer", 0, "http://www.nongnu.org/kimagemap/", "*****@*****.**");
    aboutData.addAuthor("Jan Schaefer",0, "*****@*****.**");
    aboutData.addCredit("Joerg Jaspert",I18N_NOOP("For helping me with the Makefiles, and creating the Debian package"));
    aboutData.addCredit("Aaron Seigo and Michael",I18N_NOOP("For helping me fixing --enable-final mode"));
    aboutData.addCredit("Antonio Crevillen",I18N_NOOP("For the Spanish translation"));
    aboutData.addCredit("Fabrice Mous",I18N_NOOP("For the Dutch translation"));
    aboutData.addCredit("Germain Chazot",I18N_NOOP("For the French translation"));
    KCmdLineArgs::init( argc, argv, &aboutData );
    KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.

    KApplication a;
    a.dcopClient()->registerAs(a.name());



    if (a.isRestored())
    {
        RESTORE(KimeShell);
    }
    else
    {
        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
        if ( args->count() == 0 )
        {
            KimeShell *kimeShell = new KimeShell();
            kimeShell->setStdout(args->isSet("stdout"));
            kimeShell->readConfig();
            kimeShell->show();
            kimeShell->openLastFile();
        }
        else
        {
            int i = 0;
            for (; i < args->count(); i++ )
            {
                KimeShell *kimeShell = new KimeShell();
                kimeShell->setStdout(args->isSet("stdout"));
                kimeShell->readConfig();
                kimeShell->show();
                kimeShell->openFile(args->url(i));
            }
        }
        args->clear();
    }

    return a.exec();
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
	 KLocale::setMainCatalogue("kasablanca");	

    KAboutData about("kasablanca", I18N_NOOP("kasablanca"), version, description,
                     KAboutData::License_GPL, "(C) 2004 Magnus Kulke", 0, 0,
							"*****@*****.**");
    about.addAuthor( "Magnus Kulke", 0, "*****@*****.**" );
    about.addAuthor( "Big Biff", 0, "*****@*****.**" );
	 about.addCredit( "Stefan Bogner", 0, "*****@*****.**" );
	 about.addCredit( "Christoph Thielecke", 0, "*****@*****.**" );
	about.addCredit( "Richard Stellingwerf", 0, "*****@*****.**" );
    KCmdLineArgs::init(argc, argv, &about);
    KCmdLineArgs::addCmdLineOptions(options);
    KApplication app;

    // register ourselves as a dcop client
    app.dcopClient()->registerAs(app.name(), false);

    // see if we are starting with session management
    if (app.isRestored())
    {
        RESTORE(Kasablanca);
    }
    else
    {
        // no session.. just start up normally
        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
        if (args->count() == 0)
        {
            Kasablanca *widget = new Kasablanca;
            widget->show();
        }
        else
        {
            int i = 0;
            for (; i < args->count(); i++)
            {
                Kasablanca *widget = new Kasablanca;
                widget->show();
// TODO: Load the ftp url passed on the command line.
//                widget->load(args->url(i));
            }
        }
        args->clear();
    }

    return app.exec();
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
  KCmdLineArgs::init(argc,argv,"dcoptest","dcoptest","","");
  KApplication app;
  DCOPClient &dcopclient=*(app.dcopClient());
  TiEmuDCOP_stub *tiemuDCOP;
  if (!dcopclient.attach())
    {puts("DCOP error (#1).");return 1;}
  QCStringList applist=dcopclient.registeredApplications();
  QCString appname;
  QCStringList::iterator it;
  for (it = applist.begin(); it != applist.end(); ++it) {
    if ((*it).contains(QRegExp("^tiemu-"))) {
      appname = (*it);
      break;
    }
  }
  if (appname.isNull()) { // TiEmu not running
    KRun::runCommand("tiemu");
    do {
      applist=dcopclient.registeredApplications();
      for (it = applist.begin(); it != applist.end(); ++it) {
        if ((*it).contains(QRegExp("^tiemu-"))) {
          appname = (*it);
          break;
        }
      }
    } while (appname.isNull());
  }
  tiemuDCOP = new TiEmuDCOP_stub(appname,"TiEmuDCOP");
  bool ready;
  do {
    ready=tiemuDCOP->ready_for_transfers();
    if (!tiemuDCOP->ok())
      {delete tiemuDCOP;dcopclient.detach();puts("DCOP error (#2).");return 2;}
  } while (!ready);
#if 0 // This shouldn't be needed with the new ready_for_transfers().
  if (!tiemuDCOP->turn_calc_on() || !tiemuDCOP->ok())
    {delete tiemuDCOP;dcopclient.detach();puts("DCOP error (#3).");return 3;}
  sleep(3); // give the emulated calculator time to react
#endif
  if (!tiemuDCOP->execute_command(QString("2+3")) || !tiemuDCOP->ok())
    {delete tiemuDCOP;dcopclient.detach();puts("DCOP error (#4).");return 4;}
  delete tiemuDCOP;
  if (!dcopclient.detach())
    {puts("DCOP error (#5).");return 5;}
  return 0;
}
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
    KAboutData aboutData("khc_indexbuilder", I18N_NOOP("KHelpCenter Index Builder"), HELPCENTER_VERSION, I18N_NOOP("The KDE Help Center"),
                         KAboutData::License_GPL, I18N_NOOP("(c) 2003, The KHelpCenter developers"));

    aboutData.addAuthor("Cornelius Schumacher", 0, "*****@*****.**");

    KCmdLineArgs::init(argc, argv, &aboutData);
    KCmdLineArgs::addCmdLineOptions(options);
    KUniqueApplication::addCmdLineOptions();

    KApplication app;

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

    if(args->count() != 2)
    {
        kdDebug(1402) << "Wrong number of arguments." << endl;
        return 1;
    }

    QString cmdFile = args->arg(0);
    QString indexDir = args->arg(1);

    kdDebug(1402) << "cmdFile: " << cmdFile << endl;
    kdDebug(1402) << "indexDir: " << indexDir << endl;

    QFile file(indexDir + "/testaccess");
    if(!file.open(IO_WriteOnly) || file.putch(' ') < 0)
    {
        kdDebug(1402) << "access denied" << endl;
        return 2;
    }
    else
    {
        kdDebug(1402) << "can access" << endl;
        file.remove();
    }

    app.dcopClient()->registerAs("khc_indexbuilder", false);

    IndexBuilder builder(cmdFile);

    QTimer::singleShot(0, &builder, SLOT(buildIndices()));

    return app.exec();
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
    KAboutData about("composer", I18N_NOOP("Composer"), version, description,
                     KAboutData::License_GPL, "(C) 2007 sebastian", 0, 0, "*****@*****.**");
    about.addAuthor( "sebastian", 0, "*****@*****.**" );
    KCmdLineArgs::init(argc, argv, &about);
    KCmdLineArgs::addCmdLineOptions(options);
    KApplication app;

    // register ourselves as a dcop client
    app.dcopClient()->registerAs(app.name(), false);

    // see if we are starting with session management
    if (app.isRestored())
    {
        RESTORE(Composer);
    }
    else
    {
        // no session.. just start up normally
        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
        if (args->count() == 0)
        {
            Composer *widget = new Composer;
            widget->show();
        }
        else
        {
            int i = 0;
            for (; i < args->count(); i++)
            {
                Composer *widget = new Composer;
                widget->show();
                widget->load(args->url(i));
            }
        }
        args->clear();
    }

    return app.exec();
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
    KAboutData aboutData( "kbugbuster", I18N_NOOP( "KBugBuster" ),
                          VERSION, description, KAboutData::License_GPL,
                          I18N_NOOP("(c) 2001,2002,2003 the KBugBuster authors") );
    aboutData.addAuthor( "Martijn Klingens", 0, "*****@*****.**" );
    aboutData.addAuthor( "Cornelius Schumacher", 0, "*****@*****.**" );
    aboutData.addAuthor( "Simon Hausmann", 0, "*****@*****.**" );
    aboutData.addAuthor( "David Faure", 0, "*****@*****.**" );
    KCmdLineArgs::init( argc, argv, &aboutData );
    KCmdLineArgs::addCmdLineOptions( options );

    KApplication app;

    app.dcopClient()->attach();

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    if (args->isSet("disconnected")) {
        BugSystem::self()->setDisconnected( true );
    }

    if ( app.isRestored() )
    {
        RESTORE( KBBMainWindow );
    }
    else
    {
        KBBMainWindow *mainWin = new KBBMainWindow(args->getOption("package"), args->getOption("bug"));

        // Since all background jobs remaing running after closing the
        // main window we force a quit here
        QObject::connect( &app, SIGNAL( lastWindowClosed() ),
                          &app, SLOT( quit() ) );
        mainWin->show();
        return app.exec();
    }
}
Ejemplo n.º 11
0
int main(int argc, char **argv)
{
  KAboutData about("konjue", I18N_NOOP("Konjue"), version, description,
                   KAboutData::License_GPL, "(C) 2005 Pieter Pareit", 0, 0, "*****@*****.**");
  about.addAuthor( "Pieter Pareit", 0, "*****@*****.**" );
  about.addCredit( "Pierre Sarrazin", I18N_NOOP("Programmer of Verbiste, backend used by Konjue."),
                   "sarrazip AT sarrazip DOT com", "http://sarrazip.com" );
  about.addCredit( "Sebastian Sariego Benitez", I18N_NOOP("Artist that created the icon for Konjue."),
                   "segfault AT kde DOT cl", "http://segfault.kde.cl" );
  KCmdLineArgs::init(argc, argv, &about);
  KCmdLineArgs::addCmdLineOptions(options);
  KApplication app;

  // register ourselves as a dcop client
  app.dcopClient()->registerAs(app.name(), false);

  // see if we are starting with session management
  if (app.isRestored())
  {
    RESTORE(Konjue);
  }
  else
  {
    // no session.. just start up normally, create window
    Konjue *widget = new Konjue;
    widget->show();
    // load all verbs that were give as arguments
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    for (int i = 0; i < args->count(); i++)
    {
      widget->displayVerb( args->arg( i ) );
    }
    args->clear();
  }

  return app.exec();
}
Ejemplo n.º 12
0
int main(int argc, char** argv)
{
  KAboutData about ("kdvi", I18N_NOOP("KDVI"), "1.4",
                    description, KAboutData::License_GPL,
                    "Markku Hinhala, Stephan Kebekus",
                    I18N_NOOP("This program displays Device Independent (DVI) files which are produced by the TeX typesetting system.\n"
                    "This KDVI version is based on original code from KDVI version 0.43 and xdvik."));

  about.addAuthor ("Stefan Kebekus",
                   I18N_NOOP("Current Maintainer."),
                   "*****@*****.**",
                   "http://www.mi.uni-koeln.de/~kebekus");

  about.addAuthor ("Markku Hinhala", I18N_NOOP("Author of kdvi 0.4.3"));
  about.addAuthor ("Nicolai Langfeldt", I18N_NOOP("Maintainer of xdvik"));
  about.addAuthor ("Paul Vojta", I18N_NOOP("Author of xdvi"));
  about.addCredit ("Philipp Lehmann", I18N_NOOP("Testing and bug reporting."));
  about.addCredit ("Wilfried Huss", I18N_NOOP("Re-organisation of source code."));

  KCmdLineArgs::init(argc, argv, &about);
  KCmdLineArgs::addCmdLineOptions(options);
  KApplication app;

  // see if we are starting with session management
  if (app.isRestored())
  {
    RESTORE(KViewShell);
  }
  else
  {
    KCmdLineArgs* args = KCmdLineArgs::parsedArgs();

    if (args->isSet("unique"))
    {
      // With --unique, we need 2 arguments.
      if (args->count() < 1) 
      {
        args->usage();
        exit(-1);
      }

      // Find the fully qualified file name of the file we are
      // loading. Complain, if we are given a URL which does not point
      // to a local file.
      KURL url(args->url(0));

      if (!url.isValid()) 
      {
        kdError(4300) << QString(I18N_NOOP("The URL %1 is not well-formed.")).arg(args->arg(0)) << endl;
        return -1;
      }

      if (!url.isLocalFile()) 
      {
        kdError(4300) << QString(I18N_NOOP("The URL %1 does not point to a local file. You can only specify local "
             "files if you are using the '--unique' option.")).arg(args->arg(0)) << endl;
        return -1;
      }

      QString qualPath = QFileInfo(url.path()).absFilePath();

      app.dcopClient()->attach();
      // We need to register as "kviewshell" to stay compatible with existing DCOP-skripts.
      QCString id = app.dcopClient()->registerAs("unique-kviewshell");
      if (id.isNull())
        kdError(4300) << "There was an error using dcopClient()->registerAs()." << endl;
      QCStringList apps = app.dcopClient()->registeredApplications();
      for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it ) 
      {
        if ((*it).find("kviewshell") == 0) 
        {
          QByteArray data, replyData;
          QCString replyType;
          QDataStream arg(data, IO_WriteOnly);
          bool result;
          arg << qualPath.stripWhiteSpace();
          if (!app.dcopClient()->call( *it, "kmultipage", "is_file_loaded(QString)", data, replyType, replyData))
            kdError(4300) << "There was an error using DCOP." << endl;
          else 
          {
            QDataStream reply(replyData, IO_ReadOnly);
            if (replyType == "bool") 
            {
              reply >> result;
              if (result == true) 
              {
                if (app.dcopClient()->send( *it, "kmultipage", "jumpToReference(QString)", url.ref()) == true)
                {
                  app.dcopClient()->detach();
                  return 0;
                }
              }
            }
            else
              kdError(4300) << "The DCOP function 'doIt' returned an unexpected type of reply!";
          }
        }
      }
Ejemplo n.º 13
0
/* --| main |------------------------------------------------------ */
extern "C" int KDE_EXPORT kdemain(int argc, char *argv[])
{
    setgid(getgid());
    setuid(getuid()); // drop privileges

    // deal with shell/command ////////////////////////////
    bool histon = true;
    bool menubaron = true;
    bool tabbaron = true;
    bool frameon = true;
    bool scrollbaron = true;
    bool showtip = true;

    KAboutData aboutData("konsole", I18N_NOOP("Konsole"), KONSOLE_VERSION, description, KAboutData::License_GPL_V2,
                         "Copyright (c) 1997-2006, Lars Doelle");
    aboutData.addAuthor("Robert Knight", I18N_NOOP("Maintainer"), "*****@*****.**");
    aboutData.addAuthor("Lars Doelle", I18N_NOOP("Author"), "*****@*****.**");
    aboutData.addCredit("Kurt V. Hindenburg", I18N_NOOP("bug fixing and improvements"), "*****@*****.**");
    aboutData.addCredit("Waldo Bastian", I18N_NOOP("bug fixing and improvements"), "*****@*****.**");
    aboutData.addCredit("Stephan Binner", I18N_NOOP("bug fixing and improvements"), "*****@*****.**");
    aboutData.addCredit("Chris Machemer", I18N_NOOP("bug fixing"), "*****@*****.**");
    aboutData.addCredit("Stephan Kulow", I18N_NOOP("Solaris support and work on history"), "*****@*****.**");
    aboutData.addCredit("Alexander Neundorf", I18N_NOOP("faster startup, bug fixing"), "*****@*****.**");
    aboutData.addCredit("Peter Silva", I18N_NOOP("decent marking"), "*****@*****.**");
    aboutData.addCredit("Lotzi Boloni", I18N_NOOP("partification\n"
                                                  "Toolbar and session names"),
                        "*****@*****.**");
    aboutData.addCredit("David Faure", I18N_NOOP("partification\n"
                                                 "overall improvements"),
                        "*****@*****.**");
    aboutData.addCredit("Antonio Larrosa", I18N_NOOP("transparency"), "*****@*****.**");
    aboutData.addCredit("Matthias Ettrich", I18N_NOOP("most of main.C donated via kvt\n"
                                                      "overall improvements"),
                        "*****@*****.**");
    aboutData.addCredit("Warwick Allison", I18N_NOOP("schema and selection improvements"), "*****@*****.**");
    aboutData.addCredit("Dan Pilone", I18N_NOOP("SGI Port"), "*****@*****.**");
    aboutData.addCredit("Kevin Street", I18N_NOOP("FreeBSD port"), "*****@*****.**");
    aboutData.addCredit("Sven Fischer", I18N_NOOP("bug fixing"), "*****@*****.**");
    aboutData.addCredit("Dale M. Flaven", I18N_NOOP("bug fixing"), "*****@*****.**");
    aboutData.addCredit("Martin Jones", I18N_NOOP("bug fixing"), "*****@*****.**");
    aboutData.addCredit("Lars Knoll", I18N_NOOP("bug fixing"), "*****@*****.**");
    aboutData.addCredit("", I18N_NOOP("Thanks to many others.\n"
                                      "The above list only reflects the contributors\n"
                                      "I managed to keep track of."));

    KCmdLineArgs::init(argc, argv, &aboutData);
    KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
    // 1.53 sec
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    KCmdLineArgs *qtargs = KCmdLineArgs::parsedArgs("qt");
    has_noxft = !args->isSet("xft");
    TEWidget::setAntialias(!has_noxft);
    TEWidget::setStandalone(true);

    // The following Qt options have no effect; warn users.
    if(qtargs->isSet("background"))
        kdWarning() << "The Qt option -bg, --background has no effect." << endl;
    if(qtargs->isSet("foreground"))
        kdWarning() << "The Qt option -fg, --foreground has no effect." << endl;
    if(qtargs->isSet("button"))
        kdWarning() << "The Qt option -btn, --button has no effect." << endl;
    if(qtargs->isSet("font"))
        kdWarning() << "The Qt option -fn, --font has no effect." << endl;

    KApplication *a = NULL;
#ifdef COMPOSITE
    if(args->isSet("real-transparency"))
    {
        char *display = 0;
        if(qtargs->isSet("display"))
            display = qtargs->getOption("display").data();

        Display *dpy = XOpenDisplay(display);
        if(!dpy)
        {
            kdError() << "cannot connect to X server " << display << endl;
            exit(1);
        }

        int screen = DefaultScreen(dpy);
        Colormap colormap = 0;
        Visual *visual = 0;
        int event_base, error_base;

        if(XRenderQueryExtension(dpy, &event_base, &error_base))
        {
            int nvi;
            XVisualInfo templ;
            templ.screen = screen;
            templ.depth = 32;
            templ.c_class = TrueColor;
            XVisualInfo *xvi = XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &templ, &nvi);

            for(int i = 0; i < nvi; i++)
            {
                XRenderPictFormat *format = XRenderFindVisualFormat(dpy, xvi[i].visual);
                if(format->type == PictTypeDirect && format->direct.alphaMask)
                {
                    visual = xvi[i].visual;
                    colormap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocNone);
                    kdDebug() << "found visual with alpha support" << endl;
                    argb_visual = true;
                    break;
                }
            }
        }
        // The QApplication ctor used is normally intended for applications not using Qt
        // as the primary toolkit (e.g. Motif apps also using Qt), with some slightly
        // unpleasant side effects (e.g. #83974). This code checks if qt-copy patch #0078
        // is applied, which allows turning this off.
        bool *qt_no_foreign_hack = static_cast< bool * >(dlsym(RTLD_DEFAULT, "qt_no_foreign_hack"));
        if(qt_no_foreign_hack)
            *qt_no_foreign_hack = true;
        // else argb_visual = false ... ? *shrug*

        if(argb_visual)
            a = new KApplication(dpy, Qt::HANDLE(visual), Qt::HANDLE(colormap));
        else
            XCloseDisplay(dpy);
    }
    if(a == NULL)
        a = new KApplication;
#else
    KApplication *a = new KApplication;
#endif

    QString dataPathBase = KStandardDirs::kde_default("data").append("konsole/");
    KGlobal::dirs()->addResourceType("wallpaper", dataPathBase + "wallpapers");

    KImageIO::registerFormats(); // add io for additional image formats
    // 2.1 secs

    QString title;
    if(args->isSet("T"))
    {
        title = QFile::decodeName(args->getOption("T"));
    }
    if(qtargs->isSet("title"))
    {
        title = QFile::decodeName(qtargs->getOption("title"));
    }

    QString term = "";
    if(args->isSet("tn"))
    {
        term = QString::fromLatin1(args->getOption("tn"));
    }
    login_shell = args->isSet("ls");

    QStrList eargs;

    const char *shell = 0;
    if(!args->getOption("e").isEmpty())
    {
        if(args->isSet("ls"))
            KCmdLineArgs::usage(i18n("You can't use BOTH -ls and -e.\n"));
        shell = strdup(args->getOption("e"));
        eargs.append(shell);
        for(int i = 0; i < args->count(); i++)
            eargs.append(args->arg(i));

        if(title.isEmpty() && (kapp->caption() == kapp->aboutData()->programName()))
        {
            title = QFile::decodeName(shell); // program executed in the title bar
        }
        showtip = false;
    }

    QCString sz = "";
    sz = args->getOption("vt_sz");
    histon = args->isSet("hist");
    menubaron = args->isSet("menubar");
    tabbaron = args->isSet("tabbar") && args->isSet("toolbar");
    frameon = args->isSet("frame");
    scrollbaron = args->isSet("scrollbar");
    QCString wname = qtargs->getOption("name");
    full_script = args->isSet("script");
    auto_close = args->isSet("close");
    fixed_size = !args->isSet("resize");

    if(!full_script)
        a->dcopClient()->setQtBridgeEnabled(false);

    QCString type = "";

    if(args->isSet("type"))
    {
        type = args->getOption("type");
    }
    if(args->isSet("types"))
    {
        QStringList types = KGlobal::dirs()->findAllResources("appdata", "*.desktop", false, true);
        types.sort();
        for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
        {
            QString file = *it;
            file = file.mid(file.findRev('/') + 1);
            if(file.endsWith(".desktop"))
                file = file.left(file.length() - 8);
            printf("%s\n", QFile::encodeName(file).data());
        }
        return 0;
    }
    if(args->isSet("schemas") || args->isSet("schemata"))
    {
        ColorSchemaList colors;
        colors.checkSchemas();
        for(int i = 0; i < (int)colors.count(); i++)
        {
            ColorSchema *schema = colors.find(i);
            QString relPath = schema->relPath();
            if(!relPath.isEmpty())
                printf("%s\n", QFile::encodeName(relPath).data());
        }
        return 0;
    }

    if(args->isSet("keytabs"))
    {
        QStringList lst = KGlobal::dirs()->findAllResources("data", "konsole/*.keytab");

        printf("default\n"); // 'buildin' keytab
        lst.sort();
        for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
        {
            QFileInfo fi(*it);
            QString file = fi.baseName();
            printf("%s\n", QFile::encodeName(file).data());
        }
        return 0;
    }

    QString workDir = QFile::decodeName(args->getOption("workdir"));

    QString keytab = "";
    if(args->isSet("keytab"))
        keytab = QFile::decodeName(args->getOption("keytab"));

    QString schema = "";
    if(args->isSet("schema"))
        schema = args->getOption("schema");

    KConfig *sessionconfig = 0;
    QString profile = "";
    if(args->isSet("profile"))
    {
        profile = args->getOption("profile");
        QString path = locate("data", "konsole/profiles/" + profile);
        if(QFile::exists(path))
            sessionconfig = new KConfig(path, true);
        else
            profile = "";
    }
    if(args->isSet("profiles"))
    {
        QStringList profiles = KGlobal::dirs()->findAllResources("data", "konsole/profiles/*", false, true);
        profiles.sort();
        for(QStringList::ConstIterator it = profiles.begin(); it != profiles.end(); ++it)
        {
            QString file = *it;
            file = file.mid(file.findRev('/') + 1);
            printf("%s\n", QFile::encodeName(file).data());
        }
        return 0;
    }


    // FIXME: more: font

    args->clear();

    int c = 0, l = 0;
    if(!sz.isEmpty())
    {
        char *ls = (char *)strchr(sz.data(), 'x');
        if(ls != NULL)
        {
            *ls = '\0';
            ls++;
            c = atoi(sz.data());
            l = atoi(ls);
        }
        else
        {
            KCmdLineArgs::usage(i18n("expected --vt_sz <#columns>x<#lines> e.g. 80x40\n"));
        }
    }

    if(!kapp->authorizeKAction("size"))
        fixed_size = true;

    // ///////////////////////////////////////////////

    // Ignore SIGHUP so that we don't get killed when
    // our parent-shell gets closed.
    signal(SIGHUP, SIG_IGN);

    putenv((char *)"COLORTERM="); // to trigger mc's color detection
    KonsoleSessionManaged ksm;

    if(a->isRestored() || !profile.isEmpty())
    {
        if(!shell)
            shell = konsole_shell(eargs);

        if(profile.isEmpty())
            sessionconfig = a->sessionConfig();
        sessionconfig->setDesktopGroup();
        int n = 1;

        QString key;
        QString sTitle;
        QString sPgm;
        QString sTerm;
        QString sIcon;
        QString sCwd;
        int n_tabbar;

        // TODO: Session management stores everything in same group,
        // should use one group / mainwindow
        while(KMainWindow::canBeRestored(n) || !profile.isEmpty())
        {
            sessionconfig->setGroup(QString("%1").arg(n));
            if(!sessionconfig->hasKey("Pgm0"))
                sessionconfig->setDesktopGroup(); // Backwards compatible

            int session_count = sessionconfig->readNumEntry("numSes");
            int counter = 0;

            wname = sessionconfig->readEntry("class", wname).latin1();

            sPgm = sessionconfig->readEntry("Pgm0", shell);
            sessionconfig->readListEntry("Args0", eargs);
            sTitle = sessionconfig->readEntry("Title0", title);
            sTerm = sessionconfig->readEntry("Term0");
            sIcon = sessionconfig->readEntry("Icon0", "konsole");
            sCwd = sessionconfig->readPathEntry("Cwd0");
            workDir = sessionconfig->readPathEntry("workdir");
            n_tabbar = QMIN(sessionconfig->readUnsignedNumEntry("tabbar", Konsole::TabBottom), 2);
            Konsole *m = new Konsole(wname, histon, menubaron, tabbaron, frameon, scrollbaron, 0 /*type*/, true, n_tabbar, workDir);

            m->newSession(sPgm, eargs, sTerm, sIcon, sTitle, sCwd);

            m->enableFullScripting(full_script);
            m->enableFixedSize(fixed_size);
            m->restore(n);
            sessionconfig->setGroup(QString("%1").arg(n));
            if(!sessionconfig->hasKey("Pgm0"))
                sessionconfig->setDesktopGroup(); // Backwards compatible
            m->makeGUI();
            m->setEncoding(sessionconfig->readNumEntry("Encoding0"));
            m->setSchema(sessionconfig->readEntry("Schema0"));
            // Use konsolerc default as tmpFont instead?
            QFont tmpFont = KGlobalSettings::fixedFont();
            m->initSessionFont(sessionconfig->readFontEntry("SessionFont0", &tmpFont));
            m->initSessionKeyTab(sessionconfig->readEntry("KeyTab0"));
            m->initMonitorActivity(sessionconfig->readBoolEntry("MonitorActivity0", false));
            m->initMonitorSilence(sessionconfig->readBoolEntry("MonitorSilence0", false));
            m->initMasterMode(sessionconfig->readBoolEntry("MasterMode0", false));
            m->initTabColor(sessionconfig->readColorEntry("TabColor0"));
            // -1 will be changed to the default history in konsolerc
            m->initHistory(sessionconfig->readNumEntry("History0", -1), sessionconfig->readBoolEntry("HistoryEnabled0", true));
            counter++;

            // show() before 2nd+ sessions are created allows --profile to
            //  initialize the TE size correctly.
            m->show();

            while(counter < session_count)
            {
                key = QString("Title%1").arg(counter);
                sTitle = sessionconfig->readEntry(key, title);
                key = QString("Args%1").arg(counter);
                sessionconfig->readListEntry(key, eargs);

                key = QString("Pgm%1").arg(counter);

                // if the -e option is passed on the command line, this overrides the program specified
                // in the profile file
                if(args->isSet("e"))
                    sPgm = (shell ? QFile::decodeName(shell) : QString::null);
                else
                    sPgm = sessionconfig->readEntry(key, shell);

                key = QString("Term%1").arg(counter);
                sTerm = sessionconfig->readEntry(key);
                key = QString("Icon%1").arg(counter);
                sIcon = sessionconfig->readEntry(key, "konsole");
                key = QString("Cwd%1").arg(counter);
                sCwd = sessionconfig->readPathEntry(key);
                m->newSession(sPgm, eargs, sTerm, sIcon, sTitle, sCwd);
                m->setSessionTitle(sTitle); // Use title as is
                key = QString("Schema%1").arg(counter);
                m->setSchema(sessionconfig->readEntry(key));
                key = QString("Encoding%1").arg(counter);
                m->setEncoding(sessionconfig->readNumEntry(key));
                key = QString("SessionFont%1").arg(counter);
                QFont tmpFont = KGlobalSettings::fixedFont();
                m->initSessionFont(sessionconfig->readFontEntry(key, &tmpFont));
                key = QString("KeyTab%1").arg(counter);
                m->initSessionKeyTab(sessionconfig->readEntry(key));
                key = QString("MonitorActivity%1").arg(counter);
                m->initMonitorActivity(sessionconfig->readBoolEntry(key, false));
                key = QString("MonitorSilence%1").arg(counter);
                m->initMonitorSilence(sessionconfig->readBoolEntry(key, false));
                key = QString("MasterMode%1").arg(counter);
                m->initMasterMode(sessionconfig->readBoolEntry(key, false));
                key = QString("TabColor%1").arg(counter);
                m->initTabColor(sessionconfig->readColorEntry(key));
                // -1 will be changed to the default history in konsolerc
                key = QString("History%1").arg(counter);
                QString key2 = QString("HistoryEnabled%1").arg(counter);
                m->initHistory(sessionconfig->readNumEntry(key, -1), sessionconfig->readBoolEntry(key2, true));
                counter++;
            }
            m->setDefaultSession(sessionconfig->readEntry("DefaultSession", "shell.desktop"));

            m->initFullScreen();
            if(!profile.isEmpty())
            {
                m->callReadPropertiesInternal(sessionconfig, 1);
                profile = "";
                // Hack to work-around sessions initialized with minimum size
                for(int i = 0; i < counter; i++)
                    m->activateSession(i);
                m->setColLin(c, l); // will use default height and width if called with (0,0)
            }
            // works only for the first one, but there won't be more.
            n++;
            m->activateSession(sessionconfig->readNumEntry("ActiveSession", 0));
            m->setAutoClose(auto_close);
        }
    }
    else
    {
        Konsole *m = new Konsole(wname, histon, menubaron, tabbaron, frameon, scrollbaron, type, false, 0, workDir);
        m->newSession((shell ? QFile::decodeName(shell) : QString::null), eargs, term, QString::null, title, workDir);
        m->enableFullScripting(full_script);
        m->enableFixedSize(fixed_size);
        // 3.8 :-(
        // exit(0);

        if(!keytab.isEmpty())
            m->initSessionKeyTab(keytab);

        if(!schema.isEmpty())
        {
            if(schema.right(7) != ".schema")
                schema += ".schema";
            m->setSchema(schema);
            m->activateSession(0); // Fixes BR83162, transp. schema + notabbar
        }

        m->setColLin(c, l); // will use default height and width if called with (0,0)

        m->initFullScreen();
        m->show();
        if(showtip)
            m->showTipOnStart();
        m->setAutoClose(auto_close);
    }

    int ret = a->exec();

    //// Temporary code, waiting for Qt to do this properly

    // Delete all toplevel widgets that have WDestructiveClose
    QWidgetList *list = QApplication::topLevelWidgets();
    // remove all toplevel widgets that have a parent (i.e. they
    // got WTopLevel explicitly), they'll be deleted by the parent
    list->first();
    while(list->current())
    {
        if(list->current()->parentWidget() != NULL || !list->current()->testWFlags(Qt::WDestructiveClose))
        {
            list->remove();
            continue;
        }
        list->next();
    }
    QWidgetListIt it(*list);
    QWidget *w;
    while((w = it.current()) != 0)
    {
        ++it;
        delete w;
    }
    delete list;

    delete a;

    return ret;
}