knotes

main.cpp
1 /*******************************************************************
2  KNotes -- Notes for the KDE project
3 
4  Copyright (c) 1997-2006, The KNotes Developers
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************/
20 
21 #include <tdeuniqueapplication.h>
22 #include <tdecmdlineargs.h>
23 #include <tdeaboutdata.h>
24 #include <tdelocale.h>
25 #include <kxerrorhandler.h>
26 
27 #include <X11/Xlib.h>
28 #include <X11/Xatom.h>
29 
30 #include "knotesapp.h"
31 #include "version.h"
32 #include "main.h"
33 
34 
35 void remove_sm_from_client_leader()
36 {
37  Atom type;
38  int format, status;
39  unsigned long nitems = 0;
40  unsigned long extra = 0;
41  unsigned char *data = 0;
42 
43  Atom atoms[ 2 ];
44  char *atom_names[ 2 ] = { (char*)"WM_CLIENT_LEADER", (char*)"SM_CLIENT_ID" };
45 
46  XInternAtoms( tqt_xdisplay(), atom_names, 2, False, atoms );
47 
48  TQWidget w;
49  KXErrorHandler handler; // ignore X errors
50  status = XGetWindowProperty( tqt_xdisplay(), w.winId(), atoms[ 0 ], 0, 10000,
51  FALSE, XA_WINDOW, &type, &format,
52  &nitems, &extra, &data );
53 
54  if (status == Success && !handler.error( false ))
55  {
56  if (data && nitems > 0)
57  {
58  Window leader = *((Window*) data);
59  XDeleteProperty( tqt_xdisplay(), leader, atoms[ 1 ] );
60  }
61  XFree(data);
62  }
63 }
64 
65 
66 Application::Application()
67  : TDEUniqueApplication(), mMainWindow( 0 )
68 {
69 }
70 
71 Application::~Application()
72 {
73  delete mMainWindow;
74 }
75 
76 int Application::newInstance()
77 {
78  if ( !mMainWindow )
79  {
80  mMainWindow = new KNotesApp();
81  mMainWindow->show();
82  }
83  else
84  mMainWindow->newNote();
85 
86  return TDEUniqueApplication::newInstance();
87 }
88 
89 int main( int argc, char* argv[] )
90 {
91  TQString version = TQString::number( KNOTES_VERSION );
92 
93  TDEAboutData aboutData(
94  "knotes",
95  I18N_NOOP("KNotes"),
96  version.latin1(),
97  I18N_NOOP( "TDE Notes" ),
98  TDEAboutData::License_GPL,
99  I18N_NOOP("(c) 1997-2006, The KNotes Developers")
100  );
101 
102  aboutData.addAuthor("Michael Brade", I18N_NOOP("Maintainer"), "brade@kde.org");
103  aboutData.addAuthor("Bernd Johannes Wuebben", I18N_NOOP("Original KNotes Author"), "wuebben@kde.org");
104  aboutData.addAuthor("Wynn Wilkes", I18N_NOOP("Ported KNotes to KDE 2"), "wynnw@calderasystems.com");
105  aboutData.addAuthor("Daniel Martin", I18N_NOOP("Network Interface"), "daniel.martin@pirack.com");
106  aboutData.addAuthor("Bo Thorsen", I18N_NOOP("Started KDE Resource Framework Integration"), "bo@sonofthor.dk");
107 
108  aboutData.addCredit("Bera Debajyoti", I18N_NOOP("Idea and initial code for the new look&feel"),
109  "debajyotibera@gmail.com");
110  aboutData.addCredit("Matthias Ettrich", 0, "ettrich@kde.org");
111  aboutData.addCredit("David Faure", 0, "faure@kde.org");
112  aboutData.addCredit("Matthias Kiefer", 0, "kiefer@kde.org");
113  aboutData.addCredit("Luboš Luňák", 0, "l.lunak@kde.org");
114  aboutData.addCredit("Laurent Montel", 0, "montel@kde.org");
115  aboutData.addCredit("Dirk A. Mueller", 0, "dmuell@gmx.net");
116  aboutData.addCredit("Carsten Pfeiffer", 0, "pfeiffer@kde.org");
117  aboutData.addCredit("Harri Porten", 0, "porten@kde.org");
118  aboutData.addCredit("Espen Sand", 0, "espen@kde.org");
119 
120  TDECmdLineArgs::init( argc, argv, &aboutData );
121 
122  TDEUniqueApplication::addCmdLineOptions();
123 
124  Application app;
125  app.connect( &app, TQ_SIGNAL( lastWindowClosed() ), &app, TQ_SLOT( quit() ) );
126 
127  remove_sm_from_client_leader();
128 
129  int rval = app.exec();
130 
131  return rval;
132 }