Okay, I moved all ViewUrl-related stuff into CMainWin::slot_viewurl(), replacing all other references to CICQDaemon::ViewUrl(). So we should have a uniform behavior regarding links now. The "View" button in a URL receive dialog is always shown when using KDE (since there always is a system default browser). Please have a look at the attached patch.
? autom4te.cache ? plugins/auto-reply/autom4te.cache ? plugins/console/autom4te.cache ? plugins/jons-gtk-gui/autom4te.cache ? plugins/jons-gtk-gui/config.h.in ? plugins/qt-gui/autom4te.cache ? plugins/rms/autom4te.cache Index: plugins/qt-gui/src/mainwin.cpp =================================================================== RCS file: /cvsroot/licq/qt-gui/src/mainwin.cpp,v retrieving revision 1.272 diff -u -3 -p -r1.272 mainwin.cpp --- plugins/qt-gui/src/mainwin.cpp 11 Mar 2003 16:46:49 -0000 1.272 +++ plugins/qt-gui/src/mainwin.cpp 14 Mar 2003 18:46:52 -0000 @@ -26,6 +26,7 @@ #include <kglobalsettings.h> #include <kwin.h> #include <kiconloader.h> +#include <kurl.h> #else #include <qapplication.h> #endif @@ -2090,6 +2091,7 @@ UserEventCommon *CMainWindow::callFuncti gLog.Warn("%sunknown callFunction() fcn: %d\n", L_WARNxSTR, fcn); } if(e) { + connect(e, SIGNAL(viewurl(QWidget*, QString)), this, SLOT(slot_viewurl(QWidget *, QString))); e->show(); // there might be more than one send window open // make sure we only remember one, or it will get compliated @@ -3699,6 +3701,27 @@ HintsDlg::HintsDlg(QString &hint) show(); } +// ----------------------------------------------------------------------------- + +void CMainWindow::slot_viewurl(QWidget *q, QString url) +{ +#ifdef USE_KDE + KApplication* app = static_cast<KApplication*>(qApp); + if (url.startsWith("mailto:")) + app->invokeMailer( KURL(url) ); + else + // If no URL viewer is set, use KDE default + if (licqDaemon && (!licqDaemon->getUrlViewer())) + app->invokeBrowser( url ); + else +#endif + { + if (licqDaemon == NULL) + WarnUser(q, tr("Licq is unable to find a browser application due to an internal error.")); + else if (!licqDaemon->ViewUrl(url.local8Bit().data())) + WarnUser(q, tr("Licq is unable to start your browser and open the URL.\nYou will need to start the browser and open the URL manually.")); + } +} // ----------------------------------------------------------------------------- Index: plugins/qt-gui/src/mainwin.h =================================================================== RCS file: /cvsroot/licq/qt-gui/src/mainwin.h,v retrieving revision 1.100 diff -u -3 -p -r1.100 mainwin.h --- plugins/qt-gui/src/mainwin.h 9 Mar 2003 18:25:18 -0000 1.100 +++ plugins/qt-gui/src/mainwin.h 14 Mar 2003 18:46:53 -0000 @@ -230,6 +230,7 @@ public slots: void saveOptions(); void slot_updatedList(CICQSignal *); void slot_updatedUser(CICQSignal *); + void slot_viewurl(QWidget *, QString); protected slots: void slot_hints(); Index: plugins/qt-gui/src/mlview3.cpp =================================================================== RCS file: /cvsroot/licq/qt-gui/src/mlview3.cpp,v retrieving revision 1.8 diff -u -3 -p -r1.8 mlview3.cpp --- plugins/qt-gui/src/mlview3.cpp 16 Sep 2002 23:25:44 -0000 1.8 +++ plugins/qt-gui/src/mlview3.cpp 14 Mar 2003 18:46:53 -0000 @@ -30,10 +30,6 @@ #include <qpainter.h> #include <qaccel.h> #include <qregexp.h> -#if USE_KDE -#include <kapp.h> -#include <kurl.h> -#endif #include "ewidgets.h" #include "licq_icqd.h" @@ -41,7 +37,7 @@ #include "mlview3.h" MLView::MLView (QWidget* parent, const char *name) - : QTextBrowser(parent, name), m_handleLinks(true), m_licqDaemon(NULL) + : QTextBrowser(parent, name), m_handleLinks(true) { setWordWrap(WidgetWidth); setWrapPolicy(AtWhiteSpace); @@ -147,31 +143,10 @@ void MLView::setHandleLinks(bool enable) m_handleLinks = enable; } -void MLView::setICQDaemon(CICQDaemon* licqDaemon) -{ - m_licqDaemon = licqDaemon; -} - void MLView::setSource(const QString& name) { - if (m_handleLinks) - { -#ifdef USE_KDE - KApplication* app = static_cast<KApplication*>(qApp); - if (name.find(QRegExp("^\\w+://")) > -1) - app->invokeBrowser( name ); - else if (name.startsWith("mailto:")) - app->invokeMailer( KURL(name) ); -#else - if (name.find(QRegExp("^\\w+:")) > -1) - { - if (m_licqDaemon == NULL) - WarnUser(this, tr("Licq is unable to find a browser application due to an internal error.")); - else if (!m_licqDaemon->ViewUrl(name.local8Bit().data())) - WarnUser(this, tr("Licq is unable to start your browser and open the URL.\nYou will need to start the browser and open the URL manually.")); - } -#endif - } + if (m_handleLinks && ((name.find(QRegExp("^\\w+://")) > -1) || name.startsWith("mailto:"))) + emit viewurl(this, name); } bool MLView::hasMarkedText() const Index: plugins/qt-gui/src/mlview3.h =================================================================== RCS file: /cvsroot/licq/qt-gui/src/mlview3.h,v retrieving revision 1.3 diff -u -3 -p -r1.3 mlview3.h --- plugins/qt-gui/src/mlview3.h 23 Aug 2002 05:24:40 -0000 1.3 +++ plugins/qt-gui/src/mlview3.h 14 Mar 2003 18:46:53 -0000 @@ -22,15 +22,14 @@ public: void setBackground(const QColor&); void setForeground(const QColor&); void setHandleLinks(bool enable); - void setICQDaemon(CICQDaemon* licqDaemon); static QString toRichText(const QString& s, bool highlightURLs = false); public slots: virtual void setSource(const QString& name); private: bool m_handleLinks; - // This is required for non-KDE version to be able to launch URLs. - CICQDaemon *m_licqDaemon; +signals: + void viewurl(QWidget*, QString); }; #endif Index: plugins/qt-gui/src/optionsdlg.cpp =================================================================== RCS file: /cvsroot/licq/qt-gui/src/optionsdlg.cpp,v retrieving revision 1.129 diff -u -3 -p -r1.129 optionsdlg.cpp --- plugins/qt-gui/src/optionsdlg.cpp 7 Jan 2003 05:20:37 -0000 1.129 +++ plugins/qt-gui/src/optionsdlg.cpp 14 Mar 2003 18:46:54 -0000 @@ -39,9 +39,11 @@ #include <kapp.h> #include <kfontdialog.h> #include <kurlrequester.h> +#define DEFAULT_URL_VIEWER tr("KDE default") #else #include <qapplication.h> #include <qfontdialog.h> +#define DEFAULT_URL_VIEWER tr("none") #endif #include "optionsdlg.h" @@ -322,8 +324,8 @@ void OptionsDlg::SetupOptions() chkIgnoreEmailPager->setChecked(mainwin->licqDaemon->Ignore(IGNORE_EMAILPAGER)); // plugins tab - edtUrlViewer->setText(mainwin->licqDaemon->getUrlViewer() == NULL ? - tr("none") : QString(mainwin->licqDaemon->getUrlViewer())); + cmbUrlViewer->setCurrentText(mainwin->licqDaemon->getUrlViewer() == NULL ? + DEFAULT_URL_VIEWER : QString(mainwin->licqDaemon->getUrlViewer())); edtTerminal->setText(mainwin->licqDaemon->Terminal() == NULL ? tr("none") : QString(mainwin->licqDaemon->Terminal())); @@ -531,7 +533,11 @@ void OptionsDlg::ApplyOptions() mainwin->licqDaemon->SetIgnore(IGNORE_EMAILPAGER, chkIgnoreEmailPager->isChecked()); // Plugin tab - mainwin->licqDaemon->setUrlViewer(edtUrlViewer->text().local8Bit()); + if (cmbUrlViewer->currentText() == DEFAULT_URL_VIEWER) + mainwin->licqDaemon->setUrlViewer("none"); // untranslated! + else + mainwin->licqDaemon->setUrlViewer(cmbUrlViewer->currentText().local8Bit()); + mainwin->licqDaemon->SetTerminal(edtTerminal->text().local8Bit()); if (cmbDefaultEncoding->currentItem() > 0) mainwin->m_DefaultEncoding = UserCodec::encodingForName(cmbDefaultEncoding->currentText()); @@ -1271,7 +1277,15 @@ QWidget* OptionsDlg::new_misc_options() lblUrlViewer = new QLabel(tr("Url Viewer:"), boxExtensions); QWhatsThis::add(lblUrlViewer, tr("The command to run to view a URL. Will be passed the URL " "as a parameter.")); - edtUrlViewer = new QLineEdit(boxExtensions); + cmbUrlViewer = new QComboBox(true, boxExtensions); + cmbUrlViewer->insertItem(DEFAULT_URL_VIEWER); + cmbUrlViewer->insertItem("viewurl-lynx.sh"); + cmbUrlViewer->insertItem("viewurl-mozilla.sh"); + cmbUrlViewer->insertItem("viewurl-ncftp.sh"); + cmbUrlViewer->insertItem("viewurl-netscape.sh"); + cmbUrlViewer->insertItem("viewurl-opera.sh"); + cmbUrlViewer->insertItem("viewurl-w3m.sh"); + lblTerminal = new QLabel(tr("Terminal:"), boxExtensions); edtTerminal = new QLineEdit(tr("Terminal:"), boxExtensions); QWhatsThis::add(edtTerminal, tr("The command to run to start your terminal program.")); Index: plugins/qt-gui/src/optionsdlg.h =================================================================== RCS file: /cvsroot/licq/qt-gui/src/optionsdlg.h,v retrieving revision 1.60 diff -u -3 -p -r1.60 optionsdlg.h --- plugins/qt-gui/src/optionsdlg.h 7 Jan 2003 08:00:53 -0000 1.60 +++ plugins/qt-gui/src/optionsdlg.h 14 Mar 2003 18:46:54 -0000 @@ -101,7 +101,7 @@ protected: QWidget* new_misc_options(); QGroupBox *boxParanoia, *boxExtensions; QLabel *lblUrlViewer, *lblDefaultEncoding; - QLineEdit *edtUrlViewer; + QComboBox *cmbUrlViewer; QComboBox *cmbDefaultEncoding; QLabel *lblTerminal; QLineEdit *edtTerminal; Index: plugins/qt-gui/src/usereventdlg.cpp =================================================================== RCS file: /cvsroot/licq/qt-gui/src/usereventdlg.cpp,v retrieving revision 1.109 diff -u -3 -p -r1.109 usereventdlg.cpp --- plugins/qt-gui/src/usereventdlg.cpp 11 Mar 2003 16:46:51 -0000 1.109 +++ plugins/qt-gui/src/usereventdlg.cpp 14 Mar 2003 18:46:55 -0000 @@ -343,7 +343,7 @@ UserViewEvent::UserViewEvent(CICQDaemon #if QT_VERSION < 300 mlvRead->setFormatQuoted(true); #else - mlvRead->setICQDaemon(server); + connect(mlvRead, SIGNAL(viewurl(QWidget*, QString)), mainwin, SLOT(slot_viewurl(QWidget *, QString))); #endif splRead->setResizeMode(msgView, QSplitter::FollowSizeHint); splRead->setResizeMode(mlvRead, QSplitter::Stretch); @@ -572,7 +572,9 @@ void UserViewEvent::slot_printMessage(QL btnRead1->setText(tr("&Reply")); btnRead2->setText(tr("&Quote")); btnRead3->setText(tr("&Forward")); +#ifndef USE_KDE if (server->getUrlViewer() != NULL) +#endif btnRead4->setText(tr("&View")); break; @@ -861,8 +863,7 @@ void UserViewEvent::slot_btnRead4() break; } case ICQ_CMDxSUB_URL: // view a url - if (!server->ViewUrl(((CEventUrl *)m_xCurrentReadEvent)->Url())) - WarnUser(this, tr("View URL failed")); + emit viewurl(this, ((CEventUrl *)m_xCurrentReadEvent)->Url()); break; } } @@ -1010,7 +1011,7 @@ UserSendCommon::UserSendCommon(CICQDaemo if (mainwin->m_bMsgChatView) { mleHistory = new CMessageViewWidget(_nUin, splView); #if QT_VERSION >= 300 - mleHistory->setICQDaemon(server); + connect(mleHistory, SIGNAL(viewurl(QWidget*, QString)), mainwin, SLOT(slot_viewurl(QWidget *, QString))); #endif connect (mainwin, SIGNAL(signal_sentevent(ICQEvent *)), mleHistory, SLOT(addMsg(ICQEvent *))); //splView->setResizeMode(mleHistory, QSplitter::FollowSizeHint); Index: plugins/qt-gui/src/usereventdlg.h =================================================================== RCS file: /cvsroot/licq/qt-gui/src/usereventdlg.h,v retrieving revision 1.46 diff -u -3 -p -r1.46 usereventdlg.h --- plugins/qt-gui/src/usereventdlg.h 7 Mar 2003 11:50:10 -0000 1.46 +++ plugins/qt-gui/src/usereventdlg.h 14 Mar 2003 18:46:56 -0000 @@ -100,6 +100,7 @@ protected slots: signals: void finished(unsigned long); void encodingChanged(); + void viewurl(QWidget*, QString); }; Index: plugins/qt-gui/src/userinfodlg.cpp =================================================================== RCS file: /cvsroot/licq/qt-gui/src/userinfodlg.cpp,v retrieving revision 1.64 diff -u -3 -p -r1.64 userinfodlg.cpp --- plugins/qt-gui/src/userinfodlg.cpp 13 Feb 2003 21:31:23 -0000 1.64 +++ plugins/qt-gui/src/userinfodlg.cpp 14 Mar 2003 18:46:57 -0000 @@ -970,7 +970,7 @@ void UserInfoDlg::CreateHistory() mlvHistory = new CHistoryWidget(p, "history"); #if QT_VERSION >= 300 - mlvHistory->setICQDaemon(server); + connect(mlvHistory, SIGNAL(viewurl(QWidget*, QString)), mainwin, SLOT(slot_viewurl(QWidget *, QString))); #endif lay->addWidget(mlvHistory, 1); Index: src/icqd.cpp =================================================================== RCS file: /cvsroot/licq/licq/src/icqd.cpp,v retrieving revision 1.65 diff -u -3 -p -r1.65 icqd.cpp --- src/icqd.cpp 6 Mar 2003 22:29:18 -0000 1.65 +++ src/icqd.cpp 14 Mar 2003 18:46:59 -0000 @@ -623,7 +623,7 @@ void CICQDaemon::SetAlwaysOnlineNotify(b const char *CICQDaemon::getUrlViewer() { - if (strcmp(m_szUrlViewer, "none") == 0) + if ((strcmp(m_szUrlViewer, "none") == 0) || (strlen(m_szUrlViewer) == 0)) return (NULL); else return (m_szUrlViewer); @@ -637,20 +637,41 @@ void CICQDaemon::setUrlViewer(const char bool CICQDaemon::ViewUrl(const char *u) { - if (strcmp(m_szUrlViewer, "none") == 0) return false; + if (getUrlViewer() == NULL) return false; char **arglist = (char**)malloc( 3*sizeof(char*)); arglist[0] = m_szUrlViewer; arglist[1] = (char*)u; arglist[2] = NULL; - if(!fork()) { + int pp[2]; + if (pipe(pp) < 0) return false; + + switch (fork()) { + case -1: + close(pp[0]); + close(pp[1]); + return false; + case 0: + close(pp[0]); + + // set close-on-exec flag + fcntl(pp[1], F_SETFD, 1); + execvp(arglist[0], arglist); + + // send a message indicating the failure + write(pp[1], (char *) &errno, sizeof errno); _exit(-1); } free(arglist); - return true; + close(pp[1]); + int err; + int n = read(pp[0], (char *) &err, sizeof err); + close(pp[0]); + + return (n == 0); }
ciao Jörg