1 /*************************************************************************
7 Main start file that defines 3 global vars, etc
9 *************************************************************************/
13 * 4. Send a /quit and/or kill dsirc on exit
18 #include <qsessionmanager.h>
20 #include <kuniqueapplication.h>
21 #include <kaboutdata.h>
22 #include <kcmdlineargs.h>
29 #include "servercontroller.h"
32 static const char description
[] =
33 I18N_NOOP("KDE IRC client");
35 //QDict<KSircTopLevel> TopList;
36 //QDict<KSircMessageReceiver> TopList;
38 class KCmdLineOptions options
[] =
40 { "nick <nickname>", I18N_NOOP( "Nickname to use" ), 0 } ,
41 { "server <server>", I18N_NOOP( "Server to connect to on startup" ), 0 },
42 { "channel <#channel>", I18N_NOOP( "Channel to connect to on startup" ), 0 },
44 { "noautoconnect", I18N_NOOP( "Do not autoconnect on startup" ), 0 },
48 class KSircSessionManaged
: public KSessionManaged
51 KSircSessionManaged() {}
53 virtual bool commitData( QSessionManager
&sm
)
55 servercontroller
*controller
= servercontroller::self();
56 if ( !controller
|| !sm
.allowsInteraction() ) return true;
58 // if the controller is hidden KMWSessionManaged won't send the fake close event.
59 // we want it in any way however.
60 if ( controller
->isHidden() ) {
62 QApplication::sendEvent( controller
, &e
);
69 extern "C" KDE_EXPORT
int kdemain( int argc
, char ** argv
)
71 KAboutData
aboutData( "ksirc", I18N_NOOP("KSirc"),
72 KSIRC_VERSION
, description
, KAboutData::License_Artistic
,
73 I18N_NOOP("(c) 1997-2002, The KSirc Developers"));
74 aboutData
.addAuthor("Andrew Stanley-Jones",I18N_NOOP("Original Author"), "asj-ksirc@cban.com");
75 aboutData
.addAuthor("Waldo Bastian",0, "bastian@kde.org");
76 aboutData
.addAuthor("Carsten Pfeiffer",0, "pfeiffer@kde.org");
77 aboutData
.addAuthor("Malte Starostik",0, "malte@kde.org");
78 aboutData
.addAuthor("Daniel Molkentin",0, "molkentin@kde.org");
79 aboutData
.addAuthor("Simon Hausmann",0, "hausmann@kde.org");
80 aboutData
.addAuthor("Alyssa Mejawohld", I18N_NOOP("Icons Author"), "amejawohld@bellsouth.net");
81 KCmdLineArgs::init( argc
, argv
, &aboutData
);
82 KCmdLineArgs::addCmdLineOptions( options
);
83 KUniqueApplication::addCmdLineOptions();
85 if (!KUniqueApplication::start()) {
89 // Start the KDE application
90 KUniqueApplication app
;
92 KSircSessionManaged sm
;
98 servercontroller
*sc
= new servercontroller(0, "servercontroller");
99 app
.setMainWidget(sc
);
101 if (KMainWindow::canBeRestored(1))
103 sc
->restore(1, false );
106 { // no Session management -> care about docking, geometry, etc.
108 if( !opts
.geometry
.isEmpty() )
109 sc
->setGeometry( opts
.geometry
);
111 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
113 QCString nickName
= args
->getOption( "nick" );
114 QCString server
= args
->getOption( "server" );
115 QCString channel
= args
->getOption( "channel" );
117 if ( !nickName
.isEmpty() )
118 ksopts
->server
["global"].nick
= nickName
;
120 if ( !server
.isEmpty() ) {
121 QString ser
= QString::fromLocal8Bit( server
);
122 QString port
= "6667";
123 if(ser
.contains(":")){
124 port
= ser
.section(":", 1, 1);
125 ser
= ser
.section(":", 0, 0);
127 KSircServer
kss(ser
, port
, "", "", false);
128 sc
->new_ksircprocess( kss
);
129 if ( !channel
.isEmpty() ) {
130 QStringList channels
= QStringList::split( ',', QString::fromLocal8Bit( channel
) );
131 QStringList::ConstIterator it
= channels
.begin();
132 QStringList::ConstIterator end
= channels
.end();
133 for ( ; it
!= end
; ++it
) {
134 sc
->new_toplevel( KSircChannel(ser
, *it
), true );
139 if(args
->isSet("autoconnect") == TRUE
){
140 sc
->start_autoconnect();