summaryrefslogtreecommitdiffstats
path: root/ksirc/ksirc.cpp
blob: 26de77dea6faabbeba89a946747a1ab9a9357cb4 (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
/*************************************************************************

 Main KSirc start

 $$Id$$

 Main start file that defines 3 global vars, etc

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

/*
 * Needed items
 * 4. Send a /quit and/or kill dsirc on exit
 * */

#include <stdlib.h>

#include <tqsessionmanager.h>

#include <kuniqueapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#include <tdeconfig.h>
#include <kdebug.h>

//#include "cdate.h"
#include "ksopts.h"
#include "servercontroller.h"
#include "version.h"

static const char description[] =
        I18N_NOOP("TDE IRC client");

//TQDict<KSircTopLevel> TopList;
//TQDict<KSircMessageReceiver> TopList;

class TDECmdLineOptions options[] =
{
    { "nick <nickname>", I18N_NOOP( "Nickname to use" ), 0 } ,
    { "server <server>", I18N_NOOP( "Server to connect to on startup" ), 0 },
    { "channel <#channel>", I18N_NOOP( "Channel to connect to on startup" ), 0 },
    { "o", 0, 0 },
    { "noautoconnect", I18N_NOOP( "Do not autoconnect on startup" ), 0 },
    TDECmdLineLastOption
};

class KSircSessionManaged : public KSessionManaged
{
public:
    KSircSessionManaged() {}

    virtual bool commitData( TQSessionManager &sm )
    {
        servercontroller *controller = servercontroller::self();
        if ( !controller || !sm.allowsInteraction() ) return true;

        // if the controller is hidden KMWSessionManaged won't send the fake close event.
        // we want it in any way however.
        if ( controller->isHidden() ) {
            TQCloseEvent e;
            TQApplication::sendEvent( controller, &e );
        }

        return true;
    }
};

extern "C" KDE_EXPORT int kdemain( int argc, char ** argv )
{
    TDEAboutData aboutData( "ksirc", I18N_NOOP("KSirc"),
        KSIRC_VERSION, description, TDEAboutData::License_Artistic,
        I18N_NOOP("(c) 1997-2002, The KSirc Developers"));
    aboutData.addAuthor("Andrew Stanley-Jones",I18N_NOOP("Original Author"), "asj-ksirc@cban.com");
    aboutData.addAuthor("Waldo Bastian",0, "bastian@kde.org");
    aboutData.addAuthor("Carsten Pfeiffer",0, "pfeiffer@kde.org");
    aboutData.addAuthor("Malte Starostik",0, "malte@kde.org");
    aboutData.addAuthor("Daniel Molkentin",0, "molkentin@kde.org");
    aboutData.addAuthor("Simon Hausmann",0, "hausmann@kde.org");
    aboutData.addAuthor("Alyssa Mejawohld", I18N_NOOP("Icons Author"), "amejawohld@bellsouth.net");
    TDECmdLineArgs::init( argc, argv, &aboutData );
    TDECmdLineArgs::addCmdLineOptions( options );
    KUniqueApplication::addCmdLineOptions();

    if (!KUniqueApplication::start()) {
          exit(0);
    }

    // Start the KDE application
    KUniqueApplication app;

    KSircSessionManaged sm;

    // Options
    KSOptions opts;
    opts.load();

    servercontroller *sc = new servercontroller(0, "servercontroller");
    app.setMainWidget(sc);

    if (TDEMainWindow::canBeRestored(1))
    {
        sc->restore(1, false );
    }
    else
    { // no Session management -> care about docking, geometry, etc.

        if( !opts.geometry.isEmpty() )
            sc->setGeometry( opts.geometry );

        TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();

        TQCString nickName = args->getOption( "nick" );
        TQCString server = args->getOption( "server" );
        TQCString channel = args->getOption( "channel" );

        if ( !nickName.isEmpty() )
            ksopts->server["global"].nick = nickName;

	if ( !server.isEmpty() ) {
	    TQString ser = TQString::fromLocal8Bit( server );
            TQString port = "6667";
	    if(ser.contains(":")){
		port = ser.section(":", 1, 1);
		ser = ser.section(":", 0, 0);
	    }
	    KSircServer kss(ser, port, "", "", false);
            sc->new_ksircprocess( kss  );
            if ( !channel.isEmpty() ) {
                TQStringList channels = TQStringList::split( ',', TQString::fromLocal8Bit( channel ) );
                TQStringList::ConstIterator it = channels.begin();
                TQStringList::ConstIterator end = channels.end();
		for ( ; it != end; ++it ) {
		    sc->new_toplevel( KSircChannel(ser, *it), true );
		}
            }
        }
        else {
            if(args->isSet("autoconnect") == TRUE){
                sc->start_autoconnect();
            }
        }

        args->clear();
    }

    return app.exec();
}

/* vim: et sw=4
 */