summaryrefslogtreecommitdiffstats
path: root/ksquirrel/main.cpp
blob: ba4f08cf279177b6e900c1926310aff73bae7db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/***************************************************************************
                          main.cpp  -  description
                             -------------------
    begin                : Dec 10 2003
    copyright            : (C) 2004 by Baryshev Dmitry
    email                : ksquirrel.iv@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tqgl.h>
#include <tqdir.h>
#include <tqfile.h>

#include <tdeapplication.h>
#include <tdecmdlineargs.h>
#include <tdeaboutdata.h>
#include <tdelocale.h>
#include <tdeconfig.h>
#include <dcopclient.h>
#include <tdeglobal.h>
#include <kstandarddirs.h>

#include <cstdlib>

#include "ksquirrel.h"
#include "sq_splashscreen.h"
#include "sq_hloptions.h"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

/* ****************************************************************** */

// Our command line options
static TDECmdLineOptions options[] =
{
    {"+[file to open]", I18N_NOOP("File to be opened at startup."), 0},
    {"l", I18N_NOOP("Print found libraries and exit."), 0},
    {"d", 0, 0},
    {"print-dcop", I18N_NOOP("Print available DCOP parameters"), 0},
    {"nodirectorybasket", I18N_NOOP("Folder basket"), 0},
    {"noimagebasket", I18N_NOOP("Image basket"), 0},
    {"nocategories", I18N_NOOP("Categories"), 0},
    {"nomountview", I18N_NOOP("Mount view"), 0},

    TDECmdLineLastOption
};

int main(int argc, char *argv[])
{
    KSquirrel            *SQ;
    SQ_HLOptions         *high;
    const TQCString App = "ksquirrel";

    TDEAboutData aboutData(
            "ksquirrel",
            "KSquirrel",
            VERSION,
            I18N_NOOP("KSquirrel - image viewer for TDE"),
            TDEAboutData::License_GPL,
            "(c) 2003-2007 Baryshev Dmitry",
            TQString(),
            "http://ksquirrel.sourceforge.net",
            "ksquirrel.iv@gmail.com");

    // setup 'About' dialog
    aboutData.addAuthor("Dmitry Baryshev aka Krasu", "Author", "ksquirrel.iv@gmail.com", TQString());
    aboutData.addCredit("Andrey Rahmatullin aka wrar", I18N_NOOP("Bug reports, patches"), "wrar@altlinux.ru", TQString());
    aboutData.addCredit("SeaJey", I18N_NOOP("Testing"), "seajey.serg@gmail.com", TQString());
    aboutData.addCredit("JaguarWan", I18N_NOOP("Bug reports"), "jaguarwan@gmail.com", TQString());
    aboutData.addCredit("NightGoblin", I18N_NOOP("Translation help"), 0, "http://nightgoblin.info");
    aboutData.addCredit(I18N_NOOP("TiamaT"), I18N_NOOP("Initial artwork for edit tools"), "plasticfantasy@tut.by", "http://www.livejournal.com/users/tiamatik/");
    aboutData.addCredit(I18N_NOOP("Fera"), I18N_NOOP("Great artwork for edit tools"), "morrigan171@mail.ru", TQString());
    aboutData.addCredit(I18N_NOOP("OpenGL forum at"), 0, 0, "http://opengl.org");
    aboutData.addCredit(I18N_NOOP("GameDev forum at"), 0, 0, "http://gamedev.ru");

    // parse command line
    TDECmdLineArgs::init(argc, argv, &aboutData);
    TDECmdLineArgs::addCmdLineOptions(options);
    TDECmdLineArgs *sq_args = TDECmdLineArgs::parsedArgs();

    //create high level options
    high = new SQ_HLOptions;

    if(sq_args->count())
        high->param = TQFile::decodeName(sq_args->arg(0));

    high->showLibsAndExit = sq_args->isSet("l");
    bool printDCOP = sq_args->isSet("d");

    high->have_directorybasket = sq_args->isSet("directorybasket");
    high->have_imagebasket     = sq_args->isSet("imagebasket");
    high->have_categories      = sq_args->isSet("categories");
    high->have_mountview       = sq_args->isSet("mountview");

    TDEApplication    a;

    if(!TQGLFormat::hasOpenGL())
    {
        tqWarning("KSquirrel: this system has no OpenGL support. Exiting." );
        exit(1);
    }

    // don't even try to connect to DCOP if -l specified - 
    // anyway we will exit later
    if(!high->showLibsAndExit)
    {
        bool reg = a.dcopClient()->isApplicationRegistered(App);

        // Check if KSquirrel already registered.
        // If registered, send an url to it.
        if(reg && !high->param.isEmpty())
        {
            // Yes, it is registered. Let's send a message to it.
            TQCString replyType;
            TQByteArray data, replyData;
            TQDataStream dataStream(data, IO_WriteOnly);

            dataStream << high->param;

            if(!a.dcopClient()->call(App, App, "load(TQString)", data, replyType, replyData))
                tqDebug("\nUnable to send data to old instance of KSquirrel: exiting.\n");

            sq_args->clear();
            delete high;

            exit(0);
        }
        // If registered, but no url was specified in command line
        else if(reg)
        {
            TQString data;

            if(!a.dcopClient()->send(App, App, "activate()", data))
                tqDebug("\nUnable to send data to old instance of KSquirrel: exiting.\n");

            sq_args->clear();
            delete high;

            exit(0);
        }
    }

    TDEGlobal::dirs()->addResourceType("data", TDEStandardDirs::kde_default("data") + TQString::fromLatin1("ksquirrel"));

    SQ_SplashScreen *splash = 0;

    // should we show a splash screen ?
    TDEConfig *config = new TDEConfig("ksquirrelrc");
    config->setGroup("Main");

    if(config->readBoolEntry("splash", true))
    {
        splash = new SQ_SplashScreen(0, "ksquirrel-splash-screen");
        if(!high->showLibsAndExit) splash->show(); // don't show splash when -l
        TDEApplication::flush();
    }

    delete config;

    // connect to DCOP server and register KSquirrel. Now we can
    // send messages to KSquirrel (see README for parameters)
    if(a.dcopClient()->attach())
        a.dcopClient()->registerAs(App, false);

    // create an instance
    SQ = new KSquirrel(0, App);

    if(printDCOP)
        SQ->printDCOP();

    a.setMainWidget(SQ);

    sq_args->clear();

    return a.exec();
}