• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Widgets Library
 

KDevelop Widgets Library

  • lib
  • widgets
kdevhtmlpart.cpp
1#include <tqfile.h>
2#include <tqclipboard.h>
3#include <tqapplication.h>
4
5#include <kxmlguiclient.h>
6#include <tdeaction.h>
7#include <kstdaction.h>
8#include <kstandarddirs.h>
9#include <tdelocale.h>
10#include <tdepopupmenu.h>
11#include <kiconloader.h>
12#include <tdemainwindow.h>
13#include <tdehtmlview.h>
14#include <tdehtml_settings.h>
15#include <tdeconfig.h>
16
17#include <kdevmainwindow.h>
18
19
20#include "kdevhtmlpart.h"
21
22KDevHTMLPart::KDevHTMLPart()
23 : TDEHTMLPart(0L, 0L, 0L, "KDevHTMLPart", DefaultGUI )
24{
25 setXMLFile(locate("data", "tdevelop/kdevhtml_partui.rc"), true);
26
27 connect(browserExtension(), TQ_SIGNAL(openURLRequestDelayed(const KURL &,const KParts::URLArgs &)),
28 this, TQ_SLOT(openURLRequest(const KURL &)) );
29
30 connect(this, TQ_SIGNAL(started(TDEIO::Job *)), this, TQ_SLOT(slotStarted(TDEIO::Job* )));
31 connect(this, TQ_SIGNAL(completed()), this, TQ_SLOT(slotCompleted()));
32 connect(this, TQ_SIGNAL(canceled(const TQString &)), this, TQ_SLOT(slotCancelled(const TQString &)));
33
34 TDEActionCollection * actions = actionCollection();// new TDEActionCollection( this );
35 reloadAction = new TDEAction( i18n( "Reload" ), "reload", 0,
36 this, TQ_SLOT( slotReload() ), actions, "doc_reload" );
37 reloadAction->setWhatsThis(i18n("<b>Reload</b><p>Reloads the current document."));
38 stopAction = new TDEAction( i18n( "Stop" ), "process-stop", 0,
39 this, TQ_SLOT( slotStop() ), actions, "doc_stop" );
40 stopAction->setWhatsThis(i18n("<b>Stop</b><p>Stops the loading of current document."));
41 duplicateAction = new TDEAction( i18n( "Duplicate Tab" ), "window-new", 0,
42 this, TQ_SLOT( slotDuplicate() ), actions, "doc_dup" );
43 duplicateAction->setWhatsThis(i18n("<b>Duplicate window</b><p>Opens current document in a new window."));
44 printAction = KStdAction::print(this, TQ_SLOT(slotPrint()), actions, "print_doc");
45 copyAction = KStdAction::copy(this, TQ_SLOT(slotCopy()), actions, "copy_doc_selection");
46
47 connect( this, TQ_SIGNAL(popupMenu(const TQString &, const TQPoint &)), this, TQ_SLOT(popup(const TQString &, const TQPoint &)));
48 connect(this, TQ_SIGNAL(selectionChanged()), this, TQ_SLOT(slotSelectionChanged()));
49
50//BEGIN documentation history stuff
51
52 m_backAction = new TDEToolBarPopupAction(i18n("Back"), "back", 0,
53 this, TQ_SLOT(slotBack()),
54 actions, "browser_back");
55 m_backAction->setEnabled( false );
56 m_backAction->setToolTip(i18n("Back"));
57 m_backAction->setWhatsThis(i18n("<b>Back</b><p>Moves backwards one step in the <b>documentation</b> browsing history."));
58
59 connect(m_backAction->popupMenu(), TQ_SIGNAL(aboutToShow()),
60 this, TQ_SLOT(slotBackAboutToShow()));
61 connect(m_backAction->popupMenu(), TQ_SIGNAL(activated(int)),
62 this, TQ_SLOT(slotPopupActivated(int)));
63
64 m_forwardAction = new TDEToolBarPopupAction(i18n("Forward"), "forward", 0,
65 this, TQ_SLOT(slotForward()),
66 actions, "browser_forward");
67 m_forwardAction->setEnabled( false );
68 m_forwardAction->setToolTip(i18n("Forward"));
69 m_forwardAction->setWhatsThis(i18n("<b>Forward</b><p>Moves forward one step in the <b>documentation</b> browsing history."));
70
71 connect(m_forwardAction->popupMenu(), TQ_SIGNAL(aboutToShow()),
72 this, TQ_SLOT(slotForwardAboutToShow()));
73 connect(m_forwardAction->popupMenu(), TQ_SIGNAL(activated(int)),
74 this, TQ_SLOT(slotPopupActivated(int)));
75
76 m_restoring = false;
77 m_Current = m_history.end();
78//END documentation history stuff
79
80 //settings:
81 TDEConfig *appConfig = TDEGlobal::config();
82 appConfig->setGroup("TDEHTMLPart");
83 setStandardFont(appConfig->readEntry("StandardFont",
84 settings()->stdFontName()));
85 setFixedFont(appConfig->readEntry("FixedFont",
86 settings()->fixedFontName()));
87 setZoomFactor(appConfig->readEntry("Zoom", "100").toInt());
88}
89
90void KDevHTMLPart::popup( const TQString & url, const TQPoint & p )
91{
92// TDEPopupMenu popup( i18n( "Documentation Viewer" ), this->widget() );
93 TDEPopupMenu popup(this->widget());
94
95 bool needSep = false;
96 int idNewWindow = -2;
97 if (!url.isEmpty() && (m_options & CanOpenInNewWindow))
98 {
99 idNewWindow = popup.insertItem(SmallIcon("window-new"),i18n("Open in New Tab"));
100 popup.TQMenuData::setWhatsThis(idNewWindow, i18n("<b>Open in new window</b><p>Opens current link in a new window."));
101 needSep = true;
102 }
103 if (m_options & CanDuplicate)
104 {
105 duplicateAction->plug(&popup);
106 needSep = true;
107 }
108 if (needSep)
109 popup.insertSeparator();
110
111 m_backAction->plug( &popup );
112 m_forwardAction->plug( &popup );
113 reloadAction->plug(&popup);
114// stopAction->plug(&popup);
115 popup.insertSeparator();
116
117 copyAction->plug( &popup );
118 popup.insertSeparator();
119
120 printAction->plug(&popup);
121 popup.insertSeparator();
122
123 TDEAction * incFontAction = this->action("incFontSizes");
124 TDEAction * decFontAction = this->action("decFontSizes");
125 if ( incFontAction && decFontAction )
126 {
127 incFontAction->plug( &popup );
128 decFontAction->plug( &popup );
129 popup.insertSeparator();
130 }
131
132 TDEAction *ac = action("setEncoding");
133 if (ac)
134 ac->plug(&popup);
135
136 int r = popup.exec(p);
137
138 if (r == idNewWindow)
139 {
140 KURL kurl;
141 if (!KURL(url).path().startsWith("/"))
142 {
143 kdDebug() << "processing relative url: " << url << endl;
144 if (url.startsWith("#"))
145 {
146 kurl = KURL(KDevHTMLPart::url());
147 kurl.setRef(url.mid(1));
148 }
149 else
150 kurl = KURL(KDevHTMLPart::url().upURL().url(true)+url);
151 }
152 else
153 kurl = KURL(url);
154
155 if (kurl.isValid())
156 slotOpenInNewWindow(kurl);
157 }
158}
159
160void KDevHTMLPart::setContext(const TQString &context)
161{
162 m_context = context;
163}
164
165
166TQString KDevHTMLPart::context() const
167{
168 return m_context;
169}
170
171
172// Note: this function is a copy of code in tdecore/tdeconfigbase.cpp ;)
173static bool isUtf8(const char *buf) {
174 int i, n;
175 unsigned char c;
176 bool gotone = false;
177
178#define F 0 /* character never appears in text */
179#define T 1 /* character appears in plain ASCII text */
180#define I 2 /* character appears in ISO-8859 text */
181#define X 3 /* character appears in non-ISO extended ASCII (Mac, IBM PC) */
182
183 static const unsigned char text_chars[256] = {
184 /* BEL BS HT LF FF CR */
185 F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F, /* 0x0X */
186 /* ESC */
187 F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F, /* 0x1X */
188 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x2X */
189 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x3X */
190 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x4X */
191 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x5X */
192 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, /* 0x6X */
193 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F, /* 0x7X */
194 /* NEL */
195 X, X, X, X, X, T, X, X, X, X, X, X, X, X, X, X, /* 0x8X */
196 X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, /* 0x9X */
197 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xaX */
198 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xbX */
199 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xcX */
200 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xdX */
201 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, /* 0xeX */
202 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I /* 0xfX */
203 };
204
205 /* *ulen = 0; */
206 for (i = 0; (c = buf[i]); i++) {
207 if ((c & 0x80) == 0) { /* 0xxxxxxx is plain ASCII */
208 /*
209 * Even if the whole file is valid UTF-8 sequences,
210 * still reject it if it uses weird control characters.
211 */
212
213 if (text_chars[c] != T)
214 return false;
215
216 } else if ((c & 0x40) == 0) { /* 10xxxxxx never 1st byte */
217 return false;
218 } else { /* 11xxxxxx begins UTF-8 */
219 int following;
220
221 if ((c & 0x20) == 0) { /* 110xxxxx */
222 following = 1;
223 } else if ((c & 0x10) == 0) { /* 1110xxxx */
224 following = 2;
225 } else if ((c & 0x08) == 0) { /* 11110xxx */
226 following = 3;
227 } else if ((c & 0x04) == 0) { /* 111110xx */
228 following = 4;
229 } else if ((c & 0x02) == 0) { /* 1111110x */
230 following = 5;
231 } else
232 return false;
233
234 for (n = 0; n < following; n++) {
235 i++;
236 if (!(c = buf[i]))
237 goto done;
238
239 if ((c & 0x80) == 0 || (c & 0x40))
240 return false;
241 }
242 gotone = true;
243 }
244 }
245done:
246 return gotone; /* don't claim it's UTF-8 if it's all 7-bit */
247}
248#undef F
249#undef T
250#undef I
251#undef X
252
253TQString KDevHTMLPart::resolveEnvVarsInURL(const TQString& url)
254{
255 // check for environment variables and make necessary translations
256 TQString path = url;
257 int nDollarPos = path.find( '$' );
258
259 // Note: the while loop below is a copy of code in tdecore/tdeconfigbase.cpp ;)
260 while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(path.length())) {
261 // there is at least one $
262 if( (path)[nDollarPos+1] != '$' ) {
263 uint nEndPos = nDollarPos+1;
264 // the next character is no $
265 TQString aVarName;
266 if (path[nEndPos]=='{')
267 {
268 while ( (nEndPos <= path.length()) && (path[nEndPos]!='}') )
269 nEndPos++;
270 nEndPos++;
271 aVarName = path.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
272 }
273 else
274 {
275 while ( nEndPos <= path.length() && (path[nEndPos].isNumber()
276 || path[nEndPos].isLetter() || path[nEndPos]=='_' ) )
277 nEndPos++;
278 aVarName = path.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
279 }
280 const char* pEnv = 0;
281 if (!aVarName.isEmpty())
282 pEnv = getenv( aVarName.ascii() );
283 if( pEnv ) {
284 // !!! Sergey A. Sukiyazov <corwin@micom.don.ru> !!!
285 // A environment variables may contain values in 8bit
286 // locale cpecified encoding or in UTF8 encoding.
287 if (isUtf8( pEnv ))
288 path.replace( nDollarPos, nEndPos-nDollarPos, TQString::fromUtf8(pEnv) );
289 else
290 path.replace( nDollarPos, nEndPos-nDollarPos, TQString::fromLocal8Bit(pEnv) );
291 } else
292 path.remove( nDollarPos, nEndPos-nDollarPos );
293 } else {
294 // remove one of the dollar signs
295 path.remove( nDollarPos, 1 );
296 nDollarPos++;
297 }
298 nDollarPos = path.find( '$', nDollarPos );
299 }
300
301 return path;
302}
303
304bool KDevHTMLPart::openURL(const KURL &url)
305{
306 TQString path = resolveEnvVarsInURL(url.url());
307 KURL newUrl(path);
308
309 bool retval = TDEHTMLPart::openURL(newUrl);
310 if ( retval )
311 {
312 emit fileNameChanged(this);
313 if ( !m_restoring )
314 {
315 addHistoryEntry();
316 }
317 }
318
319 m_backAction->setEnabled( m_Current != m_history.begin() );
320 m_forwardAction->setEnabled( m_Current != m_history.fromLast() );
321
322 return retval;
323}
324
325void KDevHTMLPart::openURLRequest(const KURL &url)
326{
327 openURL( url );
328}
329
330void KDevHTMLPart::slotReload( )
331{
332 openURL( url() );
333}
334
335void KDevHTMLPart::slotStop( )
336{
337 closeURL();
338}
339
340void KDevHTMLPart::slotStarted( TDEIO::Job * )
341{
342 stopAction->setEnabled(true);
343}
344
345void KDevHTMLPart::slotCompleted( )
346{
347 stopAction->setEnabled(false);
348}
349
350void KDevHTMLPart::slotCancelled( const TQString & /*errMsg*/ )
351{
352 stopAction->setEnabled(false);
353}
354
355/*void KDevHTMLPart::slotDuplicate( )
356{
357 PartController::getInstance()->showDocument(url(), true);
358}*/
359
360void KDevHTMLPart::slotPrint( )
361{
362 view()->print();
363}
364
365void KDevHTMLPart::slotBack()
366{
367 if ( m_Current != m_history.begin() )
368 {
369 --m_Current;
370 m_restoring = true;
371 openURL( (*m_Current).url );
372 m_restoring = false;
373 }
374}
375
376void KDevHTMLPart::slotForward()
377{
378 if ( m_Current != m_history.fromLast() )
379 {
380 ++m_Current;
381 m_restoring = true;
382 openURL( (*m_Current).url );
383 m_restoring = false;
384 }
385}
386
387void KDevHTMLPart::slotBackAboutToShow()
388{
389 TDEPopupMenu *popup = m_backAction->popupMenu();
390 popup->clear();
391
392 if ( m_Current == m_history.begin() ) return;
393
394 TQValueList<DocumentationHistoryEntry>::Iterator it = m_Current;
395 --it;
396
397 int i = 0;
398 while( i < 10 )
399 {
400 if ( it == m_history.begin() )
401 {
402 popup->insertItem( (*it).url.url(), (*it).id );
403 return;
404 }
405
406 popup->insertItem( (*it).url.url(), (*it).id );
407 ++i;
408 --it;
409 }
410}
411
412void KDevHTMLPart::slotForwardAboutToShow()
413{
414 TDEPopupMenu *popup = m_forwardAction->popupMenu();
415 popup->clear();
416
417 if ( m_Current == m_history.fromLast() ) return;
418
419 TQValueList<DocumentationHistoryEntry>::Iterator it = m_Current;
420 ++it;
421
422 int i = 0;
423 while( i < 10 )
424 {
425 if ( it == m_history.fromLast() )
426 {
427 popup->insertItem( (*it).url.url(), (*it).id );
428 return;
429 }
430
431 popup->insertItem( (*it).url.url(), (*it).id );
432 ++i;
433 ++it;
434 }
435}
436
437void KDevHTMLPart::slotPopupActivated( int id )
438{
439 kdDebug(9000) << "id: " << id << endl;
440
441 TQValueList<DocumentationHistoryEntry>::Iterator it = m_history.begin();
442 while( it != m_history.end() )
443 {
444 kdDebug(9000) << "(*it).id: " << (*it).id << endl;
445 if ( (*it).id == id )
446 {
447 m_Current = it;
448 m_restoring = true;
449 openURL( (*m_Current).url );
450 m_restoring = false;
451 return;
452 }
453 ++it;
454 }
455}
456
457void KDevHTMLPart::addHistoryEntry()
458{
459 TQValueList<DocumentationHistoryEntry>::Iterator it = m_Current;
460
461 // if We're not already the last entry, we truncate the list here before adding an entry
462 if ( it != m_history.end() && it != m_history.fromLast() )
463 {
464 m_history.erase( ++it, m_history.end() );
465 }
466
467 DocumentationHistoryEntry newEntry( url() );
468
469 // Only save the new entry if it is different from the last
470 if ( newEntry.url != (*m_Current).url )
471 {
472 m_history.append( newEntry );
473 m_Current = m_history.fromLast();
474 }
475}
476
477void KDevHTMLPart::slotCopy( )
478{
479 TQString text = selectedText();
480 text.replace( TQChar( 0xa0 ), ' ' );
481 TQClipboard *cb = TQApplication::clipboard();
482 disconnect( cb, TQ_SIGNAL( selectionChanged() ), this, TQ_SLOT( slotClearSelection() ) );
483 cb->setText(text);
484 connect( cb, TQ_SIGNAL( selectionChanged() ), this, TQ_SLOT( slotClearSelection() ) );
485}
486
487void KDevHTMLPart::slotSelectionChanged( )
488{
489 if (selectedText().isEmpty())
490 copyAction->setEnabled(false);
491 else
492 copyAction->setEnabled(true);
493}
494
495#include "kdevhtmlpart.moc"
kdevhtmlpart.h
Customized TDEHTML part for KDevelop.

KDevelop Widgets Library

Skip menu "KDevelop Widgets Library"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDevelop Widgets Library

Skip menu "KDevelop Widgets Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Widgets Library by doxygen 1.15.0
This website is maintained by Timothy Pearson.