File: konqplugin.cpp

package info (click to toggle)
lineak-kdeplugins 2%3A0.9-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,960 kB
  • ctags: 370
  • sloc: sh: 9,949; cpp: 3,388; perl: 2,830; makefile: 166
file content (296 lines) | stat: -rw-r--r-- 10,378 bytes parent folder | download | duplicates (3)
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/***************************************************************************
                          kdeplugin.cpp  -  description
                             -------------------
    begin                : 日 10月 26 2003
    copyright            : (C) 2003 by Sheldon Lee Wen
    email                : leewsb@hotmail.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 <qstringlist.h>
#include <qstring.h>
#include <dcopobject.h>
#include <dcopclient.h>
#include <kapplication.h>
#include <klocale.h>
#include <string>

#include "konqclient.h"

#include <config.h>
#include <lineak/lconfig.h>
#include <lineak/lkbd.h>
#include <lineak/lkey.h>
#include <lineak/lobject.h>
#include <lineak/plugin_definitions.h>
#include <lineak/displayctrl.h>

#include <iostream>
#include <sstream>
#include <stdlib.h>
using namespace std;

#include "konqplugin.h"

/** These are required */
#define NUM_MACROS 29
string konq_symbols[NUM_MACROS] = { "KONQUEROR", "KONQUEROR_SETURL", "KONQUEROR_BACK", "KONQUEROR_QUIT", "KONQUEROR_BREAKOFF_CURRENT_TAB", "KONQUEROR_DUPLICATE_WINDOW", "KONQUEROR_DUPLICATE_CURRENT_TAB", "KONQUEROR_FORWARD", "KONQUEROR_FULLSCREEN", "KONQUEROR_SIDEBAR", "KONQUEROR_HOME", "KONQUEROR_PRINT", "KONQUEROR_STOP", "KONQUEROR_REFRESH", "KONQUEROR_REMOVE_CURRENT_TAB", "KONQUEROR_REMOVEVIEW", "KONQUEROR_RELOAD", "KONQUEROR_RELOAD_ALL_TABS", "KONQUEROR_SPLITVIEW_H", "KONQUEROR_SPLITVIEW_V", "KONQUEROR_NEWTAB", "KONQUEROR_NEXTTAB", "KONQUEROR_PREVTAB", "KONQUEROR_TABMOVE_LEFT", "KONQUEROR_TABMOVE_RIGHT", "KONQUEROR_TRASH", "KONQUEROR_UNDO", "KONQUEROR_UP", "KONQUEROR_BOOKMARK" };
macro_info* konq_macinfo = NULL;
identifier_info* konq_idinfo = NULL;
bool verbose = false;
bool enable;
string dname = "";
displayCtrl* konq_Display = NULL;
DCOPClient* konq_dcop;

extern "C" int initialize(init_info init) {
        verbose = init.verbose;
	enable = init.global_enable;
	konq_dcop = new DCOPClient();
	if (!(konq_dcop->registerAs( "konqlineakdcop" )))
            if (verbose) cerr << "Could not register" << endl;
	if (!konq_dcop->attach()) {
            if (verbose) cerr << "Could not attach konq_dcop to dcop server" << endl;
        } else
            if (verbose) cout << "Registered" << endl;

	return true;
}
extern "C" identifier_info* identifier() {
	konq_idinfo = new (identifier_info);
	konq_idinfo->description = "Konqueror Plugin";
	konq_idinfo->identifier = "konqplugin";
	konq_idinfo->type = "MACRO";
	konq_idinfo->version = VERSION;
	return konq_idinfo;
}
extern "C" int exec(LObject* imyKey, XEvent xev) {
	LCommand command;
		
	if (imyKey->getType() == CODE || imyKey->getType() == SYM) {
	    command = imyKey->getCommand(xev.xkey.state);
	    dname = imyKey->getCommandDisplayName(xev.xkey.state);   
	}
        if (imyKey->getType() == BUTTON) {
	    command = imyKey->getCommand(xev.xbutton.state);
            dname = imyKey->getCommandDisplayName(xev.xbutton.state);
	}

	/* Give verbose output about the command and display name */
	if (verbose) {
		cout << "----------------------------------------" << endl;
		//cout << "For keycode: " << keycode << endl;
		cout << " Key: " << endl << *(imyKey) << endl;
                /** Note that we aren't using the display name for display here.
                    We will use the macro name instead. */
	  	cout << "	XOSD Display: " << dname << endl;
		cout << "	Command: " << command << endl;
		cout << "----------------------------------------" << endl;
	}
        if ( command.getMacroType() == "KONQUEROR" ||
             command.getMacroType() == "KONQUEROR_BACK" ||
             command.getMacroType() == "KONQUEROR_FORWARD" ||
             command.getMacroType() == "KONQUEROR_HOME" ||
             command.getMacroType() == "KONQUEROR_STOP" ||
             command.getMacroType() == "KONQUEROR_REFRESH" ||
             command.getMacroType() == "KONQUEROR_RELOAD" ||
	     command.getMacroType() == "KONQUEROR_RELOAD_ALL_TABS" ||
             command.getMacroType() == "KONQUEROR_NEWTAB" ||
             command.getMacroType() == "KONQUEROR_NEXTTAB" ||
             command.getMacroType() == "KONQUEROR_PREVTAB" ||
             command.getMacroType() == "KONQUEROR_BOOKMARK" ||
	     command.getMacroType() == "KONQUEROR_QUIT" ||
	     command.getMacroType() == "KONQUEROR_BREAKOFF_CURRENT_TAB" ||
	     command.getMacroType() == "KONQUEROR_DUPLICATE_WINDOW" ||
	     command.getMacroType() == "KONQUEROR_DUPLICATE_CURRENT_TAB" ||
	     command.getMacroType() == "KONQUEROR_FULLSCREEN" ||
	     command.getMacroType() == "KONQUEROR_SIDEBAR" ||
	     command.getMacroType() == "KONQUEROR_PRINT" ||
	     command.getMacroType() == "KONQUEROR_REMOVE_CURRENT_TAB" ||
	     command.getMacroType() == "KONQUEROR_REMOVEVIEW" ||
	     command.getMacroType() == "KONQUEROR_SPLITVIEW_H" ||
	     command.getMacroType() == "KONQUEROR_SPLITVIEW_V" ||
	     command.getMacroType() == "KONQUEROR_TABMOVE_LEFT" ||
	     command.getMacroType() == "KONQUEROR_TABMOVE_RIGHT" ||
	     command.getMacroType() == "KONQUEROR_TRASH" ||
	     command.getMacroType() == "KONQUEROR_UNDO" ||
	     command.getMacroType() == "KONQUEROR_UP" ||
             command.getMacroType() == "KONQUEROR_SETURL"
        ) { 
                macroKONQUEROR(command);
        } else if (command.isMacro())  /** If we are a macro, but we can't find one that matches, return false. */
                return false;

        if (imyKey->isUsedAsToggle())
             imyKey->toggleState();


        return true;
}
extern "C" macro_info* macrolist() {
	konq_macinfo = new (macro_info);
	konq_macinfo->num_macros = NUM_MACROS;
	konq_macinfo->macro_list = konq_symbols;
        return konq_macinfo;
}
extern "C" void cleanup() {
        if (verbose) cout << "Cleaning up plugin konqueror" << endl;
	if (konq_macinfo != NULL) {
		delete (konq_macinfo);
		konq_macinfo = NULL;
	}
	if (konq_idinfo != NULL) {
		delete (konq_idinfo);
		konq_idinfo = NULL;
	}
 	if (konq_dcop != NULL) {
		konq_dcop->detach();
 		delete(konq_dcop);
 		konq_dcop = NULL;
 	}
	if (verbose) cout << "Done cleaning up plugin konqueror" << endl;
}
extern "C" int initialize_display(displayCtrl *imyDisplay) {
        if (verbose) cout << "Initializing on screen display!" << endl;
        konq_Display = imyDisplay;
	return true;
}

bool macroKONQUEROR(LCommand& command) {
   if (enable) {
	const vector<std::string>& args = command.getArgs();

	QCString objid;
    	QCString function;
        QByteArray data;
	QCString foundApp;
	QCString foundObj;

	KonqClient konq(konq_dcop);
	if (!konq.isRunning()) {
	   if (!konq.startKonqueror()) {
              if (KApplication::startServiceByDesktopName("konqueror")) {
	         cout << i18n("No running instance of konqueror found.");
              }
           }
	}
        QString comm;
	if (args.size() == 1) {
           if (command.getMacroType() == "KONQUEROR_SETURL") {
              comm = "SETURL";
           } else
	      comm = QString((args[0]).c_str());
	}
	else if (args.size() == 0) {
	   string tmp = command.getCommand();
	   int loc = tmp.find("_");
	   comm = QString(tmp.substr(loc+1,tmp.size()).c_str());
	   //comm = QString(tmp.substr(loc+1,tmp.size()));
	}
	else
	   return false;
	   
	   if (dname == "" || dname == snull)
              dname = comm.latin1();

	   if ( comm.upper() == "BACK" ) {
	      konq.back();
	   }
	   else if ( comm.upper() == "FORWARD" ) {
	      konq.forward();
	   }
	   else if ( comm.upper() == "HOME" ) {
	      konq.home();
	   }
	   else if ( comm.upper() == "STOP" ) {
	      konq.stop();
	   }
	   else if ( comm.upper() == "REFRESH" || comm.upper() == "RELOAD" ) {
	      konq.refresh();
	   }
	   else if ( comm.upper() == "RELOAD_ALL_TABS" ) {
	      konq.reload_all_tabs();
	   }
	   else if ( comm.upper() == "NEWTAB" ) {
	      konq.newtab();
	   }
	   else if ( comm.upper() == "NEXTTAB") {
	      konq.nexttab();
	   }
	   else if ( comm.upper() == "PREVIOUSTAB") {
	      konq.previoustab();
	   }
	   else if ( comm.upper() == "BOOKMARK" ) {
	      konq.addBookmark();
	   }
	   else if ( comm.upper() == "QUIT" ) {
	      konq.quit();
	   }
	   else if ( comm.upper() == "BREAKOFF_CURRENT_TAB" ) {
	      konq.breakoffcurrenttab();
	   }
           else if ( comm.upper() == "DUPLICATE_WINDOW" ) {
	      konq.duplicate_window();
	   }
           else if ( comm.upper() == "DUPLICATE_CURRENT_TAB" ) { 
	      konq.duplicatecurrenttab();
	   }
	   else if ( comm.upper() == "FULLSCREEN" ) {
	      konq.fullscreen();
	   }
	   else if ( comm.upper() == "SIDEBAR" ) {
              konq.konq_sidebartng();
	   }
	   else if ( comm.upper() == "PRINT" ) {
              konq.print();
	   }
	   else if ( comm.upper() == "REMOVE_CURRENT_TAB" ) {
              konq.removecurrenttab();
	   }
	   else if ( comm.upper() == "REMOVEVIEW" ) {
              konq.removeview();
	   }
	   else if ( comm.upper() == "SPLITVIEW_H" ) {
              konq.splitviewh();
	   }
	   else if ( comm.upper() == "SPLITVIEW_V" ) {
	      konq.splitviewv();
           }	   
	   else if ( comm.upper() == "TABMOVE_LEFT" ) {
              konq.tab_move_left();
	   }	   
	   else if ( comm.upper() == "TABMOVE_RIGHT" ) {
              konq.tab_move_right();
	   }	   
	   else if ( comm.upper() == "TRASH" ) {
              konq.trash();
	   }	   
	   else if ( comm.upper() == "UNDO" ) {
              konq.undo();
	   }	   
	   else if ( comm.upper() == "UP") {
              konq.up();
           }
           else if ( comm.upper() == "SETURL") {
              konq.setURL(args[0]);
	   } else {
	      if (verbose) {
		cerr << comm << " is an unknown KONQUEROR macro argument." << endl;
	      }
	      return false;
	   }
	konq_Display->show(dname);
   }
   return true;
   
//   return false;
}