26 #include <tdeaction.h>
27 #include <tdeapplication.h>
28 #include <tdefiledialog.h>
29 #include <tdehtmlview.h>
30 #include <kiconloader.h>
31 #include <tdelocale.h>
32 #include <tdemessagebox.h>
33 #include <tdepopupmenu.h>
34 #include <tdeprocess.h>
38 #include <tdeparts/browserextension.h>
41 #include <tqclipboard.h>
42 #include <tqpaintdevicemetrics.h>
45 #include "akregator_run.h"
46 #include "akregatorconfig.h"
50 Viewer::Viewer(TQWidget *parent,
const char *name)
51 : TDEHTMLPart(parent, name), m_url(0)
54 setMetaRefreshEnabled(
true);
56 setAutoloadImages(
true);
57 setStatusMessagesEnabled(
true);
60 connect(
this, TQ_SIGNAL(started(TDEIO::Job *)),
61 this, TQ_SLOT(slotStarted(TDEIO::Job *)));
62 connect(
this, TQ_SIGNAL(completed()),
63 this, TQ_SLOT(slotCompleted()));
65 connect( browserExtension(), TQ_SIGNAL(popupMenu (KXMLGUIClient*,
const TQPoint&,
const KURL&,
const KParts::URLArgs&, KParts::BrowserExtension::PopupFlags, mode_t)),
this, TQ_SLOT(slotPopupMenu(KXMLGUIClient*,
const TQPoint&,
const KURL&,
const KParts::URLArgs&, KParts::BrowserExtension::PopupFlags, mode_t)));
67 KStdAction::print(
this, TQ_SLOT(slotPrint()), actionCollection(),
"viewer_print");
68 KStdAction::copy(
this, TQ_SLOT(slotCopy()), actionCollection(),
"viewer_copy");
70 new TDEAction( i18n(
"&Increase Font Sizes"),
"zoom-in",
"Ctrl+Plus",
this, TQ_SLOT(slotZoomIn()), actionCollection(),
"incFontSizes" );
71 new TDEAction( i18n(
"&Decrease Font Sizes"),
"zoom-out",
"Ctrl+Minus",
this, TQ_SLOT(slotZoomOut()), actionCollection(),
"decFontSizes" );
73 connect(
this, TQ_SIGNAL(selectionChanged()),
this, TQ_SLOT(slotSelectionChanged()));
75 connect( browserExtension(), TQ_SIGNAL(openURLRequestDelayed(
const KURL&,
const KParts::URLArgs&)),
this, TQ_SLOT(slotOpenURLRequest(
const KURL&,
const KParts::URLArgs& )) );
77 new TDEAction(i18n(
"Copy &Link Address"),
"", 0,
78 this, TQ_SLOT(slotCopyLinkAddress()),
79 actionCollection(),
"copylinkaddress");
80 new TDEAction(i18n(
"&Save Link As..."),
"", 0,
81 this, TQ_SLOT(slotSaveLinkAs()),
82 actionCollection(),
"savelinkas");
88 bool Viewer::closeURL()
90 emit browserExtension()->loadingProgress(-1);
91 emit canceled(TQString());
92 return TDEHTMLPart::closeURL();
95 int Viewer::pointsToPixel(
int pointSize)
const
97 const TQPaintDeviceMetrics metrics(view());
98 return ( pointSize * metrics.logicalDpiY() + 36 ) / 72 ;
101 void Viewer::displayInExternalBrowser(
const KURL &url,
const TQString &mimetype)
103 if (!url.isValid())
return;
104 if (Settings::externalBrowserUseTdeDefault())
106 if (mimetype.isEmpty())
107 kapp->invokeBrowser(url.url(),
"0");
109 KRun::runURL(url, mimetype,
false,
false);
113 TQString cmd = Settings::externalBrowserCustomCommand();
114 TQString urlStr = url.url();
115 cmd.replace(TQRegExp(
"%u"), urlStr);
116 TDEProcess *proc =
new TDEProcess;
117 TQStringList cmdAndArgs = KShell::splitArgs(cmd);
119 proc->start(TDEProcess::DontCare);
124 void Viewer::slotOpenURLRequest(
const KURL& ,
const KParts::URLArgs& )
129 void Viewer::urlSelected(
const TQString &url,
int button,
int state,
const TQString &_target, KParts::URLArgs args)
131 m_url = completeURL(url);
132 browserExtension()->setURLArgs(args);
133 if (button == TQt::LeftButton)
135 switch (Settings::lMBBehaviour())
137 case Settings::EnumLMBBehaviour::OpenInExternalBrowser:
138 slotOpenLinkInBrowser();
140 case Settings::EnumLMBBehaviour::OpenInBackground:
141 slotOpenLinkInBackgroundTab();
144 slotOpenLinkInForegroundTab();
149 else if (button == TQt::MidButton)
151 switch (Settings::mMBBehaviour())
153 case Settings::EnumMMBBehaviour::OpenInExternalBrowser:
154 slotOpenLinkInBrowser();
156 case Settings::EnumMMBBehaviour::OpenInBackground:
157 slotOpenLinkInBackgroundTab();
160 slotOpenLinkInForegroundTab();
165 TDEHTMLPart::urlSelected(url,button,state,_target,args);
168 void Viewer::slotPopupMenu(KXMLGUIClient*,
const TQPoint& p,
const KURL& kurl,
const KParts::URLArgs&, KParts::BrowserExtension::PopupFlags kpf, mode_t)
170 const bool isLink = (kpf & (KParts::BrowserExtension::ShowNavigationItems | KParts::BrowserExtension::ShowTextSelectionItems)) == 0;
171 const bool isSelection = (kpf & KParts::BrowserExtension::ShowTextSelectionItems) != 0;
173 TQString url = kurl.url();
178 if (isLink && !isSelection)
180 popup.insertItem(SmallIcon(
"tab_new"), i18n(
"Open Link in New &Tab"),
this, TQ_SLOT(slotOpenLinkInForegroundTab()));
181 popup.insertItem(SmallIcon(
"window-new"), i18n(
"Open Link in External &Browser"),
this, TQ_SLOT(slotOpenLinkInBrowser()));
182 popup.insertSeparator();
183 action(
"savelinkas")->plug(&popup);
184 action(
"copylinkaddress")->plug(&popup);
190 action(
"viewer_copy")->plug(&popup);
191 popup.insertSeparator();
193 action(
"viewer_print")->plug(&popup);
202 void Viewer::slotCopy()
204 TQString text = selectedText();
205 text.replace( TQChar( 0xa0 ),
' ' );
206 TQClipboard *cb = TQApplication::clipboard();
207 disconnect( cb, TQ_SIGNAL( selectionChanged() ),
this, TQ_SLOT( slotClearSelection() ) );
209 connect( cb, TQ_SIGNAL( selectionChanged() ),
this, TQ_SLOT( slotClearSelection() ) );
212 void Viewer::slotCopyLinkAddress()
214 if(m_url.isEmpty())
return;
215 TQClipboard *cb = TQApplication::clipboard();
216 cb->setText(m_url.prettyURL(), TQClipboard::Clipboard);
217 cb->setText(m_url.prettyURL(), TQClipboard::Selection);
220 void Viewer::slotSelectionChanged()
222 action(
"viewer_copy")->setEnabled(!selectedText().isEmpty());
225 void Viewer::slotOpenLinkInternal()
230 void Viewer::slotOpenLinkInForegroundTab()
232 emit urlClicked(m_url,
this,
true,
false);
235 void Viewer::slotOpenLinkInBackgroundTab()
237 emit urlClicked(m_url,
this,
true,
true);
240 void Viewer::slotOpenLinkInThisTab()
242 emit urlClicked(m_url,
this,
false,
false);
245 void Viewer::slotOpenLinkInBrowser()
247 displayInExternalBrowser(m_url, TQString());
250 void Viewer::slotSaveLinkAs()
254 if ( tmp.fileName(
false).isEmpty() )
255 tmp.setFileName(
"index.html" );
256 KParts::BrowserRun::simpleSave(tmp, tmp.fileName());
259 void Viewer::slotStarted(TDEIO::Job *)
261 widget()->setCursor( waitCursor );
264 void Viewer::slotCompleted()
266 widget()->unsetCursor();
269 void Viewer::slotScrollUp()
271 view()->scrollBy(0,-10);
274 void Viewer::slotScrollDown()
276 view()->scrollBy(0,10);
279 void Viewer::slotZoomIn()
281 int zf = zoomFactor();
284 zf = zf - (zf % 20) + 20;
289 zf = zf - (zf % 50) + 50;
290 setZoomFactor(zf < 300 ? zf : 300);
294 void Viewer::slotZoomOut()
296 int zf = zoomFactor();
299 zf = zf - (zf % 20) - 20;
300 setZoomFactor(zf > 20 ? zf : 20);
304 zf = zf - (zf % 50) - 50;
309 void Viewer::slotSetZoomFactor(
int percent)
311 setZoomFactor(percent);
315 void Viewer::slotPrint( )
321 void Viewer::setSafeMode()
324 setJavaEnabled(
false);
325 setMetaRefreshEnabled(
false);
326 setPluginsEnabled(
false);
328 setAutoloadImages(
true);
329 setStatusMessagesEnabled(
false);
334 #include "viewer.moc"