2 #include <tqclipboard.h> 3 #include <tqapplication.h> 5 #include <kxmlguiclient.h> 7 #include <kstdaction.h> 8 #include <kstandarddirs.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> 17 #include <kdevmainwindow.h> 22 KDevHTMLPart::KDevHTMLPart()
23 : TDEHTMLPart(0L, 0L, 0L,
"KDevHTMLPart", DefaultGUI )
25 setXMLFile(locate(
"data",
"tdevelop/kdevhtml_partui.rc"),
true);
27 connect(browserExtension(), TQT_SIGNAL(openURLRequestDelayed(
const KURL &,
const KParts::URLArgs &)),
28 this, TQT_SLOT(openURLRequest(
const KURL &)) );
30 connect(
this, TQT_SIGNAL(started(TDEIO::Job *)),
this, TQT_SLOT(slotStarted(TDEIO::Job* )));
31 connect(
this, TQT_SIGNAL(completed()),
this, TQT_SLOT(slotCompleted()));
32 connect(
this, TQT_SIGNAL(canceled(
const TQString &)),
this, TQT_SLOT(slotCancelled(
const TQString &)));
34 TDEActionCollection * actions = actionCollection();
35 reloadAction =
new TDEAction( i18n(
"Reload" ),
"reload", 0,
36 this, TQT_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, TQT_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, TQT_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, TQT_SLOT(slotPrint()), actions,
"print_doc");
45 copyAction = KStdAction::copy(
this, TQT_SLOT(slotCopy()), actions,
"copy_doc_selection");
47 connect(
this, TQT_SIGNAL(popupMenu(
const TQString &,
const TQPoint &)),
this, TQT_SLOT(popup(
const TQString &,
const TQPoint &)));
48 connect(
this, TQT_SIGNAL(selectionChanged()),
this, TQT_SLOT(slotSelectionChanged()));
52 m_backAction =
new TDEToolBarPopupAction(i18n(
"Back"),
"back", 0,
53 this, TQT_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."));
59 connect(m_backAction->popupMenu(), TQT_SIGNAL(aboutToShow()),
60 this, TQT_SLOT(slotBackAboutToShow()));
61 connect(m_backAction->popupMenu(), TQT_SIGNAL(activated(
int)),
62 this, TQT_SLOT(slotPopupActivated(
int)));
64 m_forwardAction =
new TDEToolBarPopupAction(i18n(
"Forward"),
"forward", 0,
65 this, TQT_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."));
71 connect(m_forwardAction->popupMenu(), TQT_SIGNAL(aboutToShow()),
72 this, TQT_SLOT(slotForwardAboutToShow()));
73 connect(m_forwardAction->popupMenu(), TQT_SIGNAL(activated(
int)),
74 this, TQT_SLOT(slotPopupActivated(
int)));
77 m_Current = m_history.end();
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());
90 void KDevHTMLPart::popup(
const TQString & url,
const TQPoint & p )
93 TDEPopupMenu popup(this->widget());
97 if (!url.isEmpty() && (m_options & CanOpenInNewWindow))
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."));
103 if (m_options & CanDuplicate)
105 duplicateAction->plug(&popup);
109 popup.insertSeparator();
111 m_backAction->plug( &popup );
112 m_forwardAction->plug( &popup );
113 reloadAction->plug(&popup);
115 popup.insertSeparator();
117 copyAction->plug( &popup );
118 popup.insertSeparator();
120 printAction->plug(&popup);
121 popup.insertSeparator();
123 TDEAction * incFontAction = this->action(
"incFontSizes");
124 TDEAction * decFontAction = this->action(
"decFontSizes");
125 if ( incFontAction && decFontAction )
127 incFontAction->plug( &popup );
128 decFontAction->plug( &popup );
129 popup.insertSeparator();
132 TDEAction *ac = action(
"setEncoding");
136 int r = popup.exec(p);
138 if (r == idNewWindow)
141 if (!KURL(url).path().startsWith(
"/"))
143 kdDebug() <<
"processing relative url: " << url << endl;
144 if (url.startsWith(
"#"))
146 kurl = KURL(KDevHTMLPart::url());
147 kurl.setRef(url.mid(1));
150 kurl = KURL(KDevHTMLPart::url().upURL().url(
true)+url);
156 slotOpenInNewWindow(kurl);
160 void KDevHTMLPart::setContext(
const TQString &context)
166 TQString KDevHTMLPart::context()
const 173 static bool isUtf8(
const char *buf) {
175 register unsigned char c;
183 static const unsigned char text_chars[256] = {
185 F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F,
187 F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F,
188 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
189 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
190 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
191 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
192 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
193 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F,
195 X, X, X, X, X, T, X, X, X, X, X, X, X, X, X, X,
196 X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X,
197 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
198 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
199 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
200 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
201 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
202 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I
206 for (i = 0; (c = buf[i]); i++) {
207 if ((c & 0x80) == 0) {
213 if (text_chars[c] != T)
216 }
else if ((c & 0x40) == 0) {
221 if ((c & 0x20) == 0) {
223 }
else if ((c & 0x10) == 0) {
225 }
else if ((c & 0x08) == 0) {
227 }
else if ((c & 0x04) == 0) {
229 }
else if ((c & 0x02) == 0) {
234 for (n = 0; n < following; n++) {
239 if ((c & 0x80) == 0 || (c & 0x40))
253 TQString KDevHTMLPart::resolveEnvVarsInURL(
const TQString& url)
257 int nDollarPos = path.find(
'$' );
260 while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(path.length())) {
262 if( (path)[nDollarPos+1] ==
'(' ) {
263 uint nEndPos = nDollarPos+1;
265 while ( (nEndPos <= path.length()) && (path[nEndPos]!=
')') )
268 TQString cmd = path.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
271 FILE *fs = popen(TQFile::encodeName(cmd).data(),
"r");
274 TQTextStream ts(fs, IO_ReadOnly);
275 result = ts.read().stripWhiteSpace();
278 path.replace( nDollarPos, nEndPos-nDollarPos, result );
279 }
else if( (path)[nDollarPos+1] !=
'$' ) {
280 uint nEndPos = nDollarPos+1;
283 if (path[nEndPos]==
'{')
285 while ( (nEndPos <= path.length()) && (path[nEndPos]!=
'}') )
288 aVarName = path.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
292 while ( nEndPos <= path.length() && (path[nEndPos].isNumber()
293 || path[nEndPos].isLetter() || path[nEndPos]==
'_' ) )
295 aVarName = path.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
297 const char* pEnv = 0;
298 if (!aVarName.isEmpty())
299 pEnv = getenv( aVarName.ascii() );
305 path.replace( nDollarPos, nEndPos-nDollarPos, TQString::fromUtf8(pEnv) );
307 path.replace( nDollarPos, nEndPos-nDollarPos, TQString::fromLocal8Bit(pEnv) );
309 path.remove( nDollarPos, nEndPos-nDollarPos );
312 path.remove( nDollarPos, 1 );
315 nDollarPos = path.find(
'$', nDollarPos );
321 bool KDevHTMLPart::openURL(
const KURL &url)
323 TQString path = resolveEnvVarsInURL(url.url());
326 bool retval = TDEHTMLPart::openURL(newUrl);
329 emit fileNameChanged(
this);
336 m_backAction->setEnabled( m_Current != m_history.begin() );
337 m_forwardAction->setEnabled( m_Current != m_history.fromLast() );
342 void KDevHTMLPart::openURLRequest(
const KURL &url)
347 void KDevHTMLPart::slotReload( )
352 void KDevHTMLPart::slotStop( )
357 void KDevHTMLPart::slotStarted( TDEIO::Job * )
359 stopAction->setEnabled(
true);
362 void KDevHTMLPart::slotCompleted( )
364 stopAction->setEnabled(
false);
367 void KDevHTMLPart::slotCancelled(
const TQString & )
369 stopAction->setEnabled(
false);
377 void KDevHTMLPart::slotPrint( )
382 void KDevHTMLPart::slotBack()
384 if ( m_Current != m_history.begin() )
388 openURL( (*m_Current).url );
393 void KDevHTMLPart::slotForward()
395 if ( m_Current != m_history.fromLast() )
399 openURL( (*m_Current).url );
404 void KDevHTMLPart::slotBackAboutToShow()
406 TDEPopupMenu *popup = m_backAction->popupMenu();
409 if ( m_Current == m_history.begin() )
return;
411 TQValueList<DocumentationHistoryEntry>::Iterator it = m_Current;
417 if ( it == m_history.begin() )
419 popup->insertItem( (*it).url.url(), (*it).id );
423 popup->insertItem( (*it).url.url(), (*it).id );
429 void KDevHTMLPart::slotForwardAboutToShow()
431 TDEPopupMenu *popup = m_forwardAction->popupMenu();
434 if ( m_Current == m_history.fromLast() )
return;
436 TQValueList<DocumentationHistoryEntry>::Iterator it = m_Current;
442 if ( it == m_history.fromLast() )
444 popup->insertItem( (*it).url.url(), (*it).id );
448 popup->insertItem( (*it).url.url(), (*it).id );
454 void KDevHTMLPart::slotPopupActivated(
int id )
456 kdDebug(9000) <<
"id: " <<
id << endl;
458 TQValueList<DocumentationHistoryEntry>::Iterator it = m_history.begin();
459 while( it != m_history.end() )
461 kdDebug(9000) <<
"(*it).id: " << (*it).id << endl;
462 if ( (*it).id ==
id )
466 openURL( (*m_Current).url );
474 void KDevHTMLPart::addHistoryEntry()
476 TQValueList<DocumentationHistoryEntry>::Iterator it = m_Current;
479 if ( it != m_history.end() && it != m_history.fromLast() )
481 m_history.erase( ++it, m_history.end() );
484 DocumentationHistoryEntry newEntry( url() );
487 if ( newEntry.url != (*m_Current).url )
489 m_history.append( newEntry );
490 m_Current = m_history.fromLast();
494 void KDevHTMLPart::slotCopy( )
496 TQString text = selectedText();
497 text.replace( TQChar( 0xa0 ),
' ' );
498 TQClipboard *cb = TQApplication::clipboard();
499 disconnect( cb, TQT_SIGNAL( selectionChanged() ),
this, TQT_SLOT( slotClearSelection() ) );
501 connect( cb, TQT_SIGNAL( selectionChanged() ),
this, TQT_SLOT( slotClearSelection() ) );
504 void KDevHTMLPart::slotSelectionChanged( )
506 if (selectedText().isEmpty())
507 copyAction->setEnabled(
false);
509 copyAction->setEnabled(
true);
512 #include "kdevhtmlpart.moc" Customized TDEHTML part for KDevelop.