Browse Source

Drop custom AssistantClient, as it uses deprecated (KProcIO) and removed (KExtendedSocket) KDE classes, and the workaround shouldn't be needed anymore in Qt/KDE 4.

git-svn-id: file:///var/svn/tigccpp/trunk@959 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 17 years ago
parent
commit
9f5e16ac3f
7 changed files with 23 additions and 244 deletions
  1. 0 181
      ktigcc/assistant.cpp
  2. 0 46
      ktigcc/assistant.h
  3. 2 2
      ktigcc/ktigcc.h
  4. 1 3
      ktigcc/ktigcc.pro
  5. 10 6
      ktigcc/mainform.cpp
  6. 5 3
      ktigcc/programoptions.cpp
  7. 5 3
      ktigcc/srcfilewin.cpp

+ 0 - 181
ktigcc/assistant.cpp

@@ -1,181 +0,0 @@
-/*
-   ktigcc - TIGCC IDE for KDE
-
-   Copyright (C) 2006-2007 Kevin Kofler
-
-   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, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
-*/
-
-// This class is like QAssistantClient, but simpler (taylored to KTIGCC's use)
-// and uses KProcess and KExtendedSocket instead of QProcess and QSocket. This
-// is needed because, very annoyingly, QProcess doesn't work together with
-// KProcess.
-
-#include "assistant.h"
-#include <kprocio.h>
-#include <kextsock.h>
-#include <kmessagebox.h>
-#include <qtextcodec.h>
-#include <qwidget.h>
-#include <qapplication.h>
-#include <qeventloop.h>
-#include <q3textstream.h>
-#include <unistd.h>
-
-AssistantClient::AssistantClient(QObject *parent, const QString &profile)
-  : QObject(parent), parentWidget(0), procIO(0), socket(0),
-    assistantProfile(profile)
-{
-  if (parent->isWidgetType()) parentWidget=static_cast<QWidget *>(parent);
-}
-
-AssistantClient::~AssistantClient()
-{
-  int socketStatus=socket?socket->socketStatus():0;
-  if (socketStatus && socketStatus<KExtendedSocket::lookupInProgress) {
-    KMessageBox::error(parentWidget,socket->strError(socketStatus,
-                                                     socket->systemError()),
-                       "Socket Error");
-  }
-  if (procIO) {
-    procIO->kill();
-    usleep(100000);
-    delete procIO;
-  }
-  if (socket) delete socket;
-}
-
-void AssistantClient::openAssistant(const QString &page)
-{
-  int socketStatus=socket?socket->socketStatus():0;
-  if (socketStatus && socketStatus<KExtendedSocket::lookupInProgress) {
-    KMessageBox::error(parentWidget,socket->strError(socketStatus,
-                                                     socket->systemError()),
-                       "Socket Error");
-    procIO->kill();
-    usleep(100000);
-    delete procIO;
-    procIO=static_cast<KProcIO *>(NULL);
-    return;
-  }
-  if (socketStatus>=KExtendedSocket::closing) {
-    // The old process is not closed yet, but the connection was already lost.
-    // So kill the old process now and run a new one.
-    procIO->kill();
-    usleep(100000);
-    delete procIO;
-    procIO=static_cast<KProcIO *>(NULL);
-    delete socket;
-    socket=static_cast<KExtendedSocket *>(NULL);
-  }
-  if (!procIO) {
-    start_new:
-    // The QTextCodec has to be passed explicitly, or it will default to
-    // ISO-8859-1 regardless of the locale, which is just broken.
-    procIO=new KProcIO(QTextCodec::codecForLocale());
-    // Use MergedStderr instead of Stderr so the messages get ordered
-    // properly.
-    procIO->setComm(static_cast<KProcess::Communication>(
-      KProcess::Stdout|KProcess::MergedStderr));
-    (*procIO)<<"assistant"<<"-server";
-    if (!assistantProfile.isNull())
-      (*procIO)<<"-profile"<<assistantProfile;
-    if (!page.isNull())
-      (*procIO)<<"-file"<<page;
-    connect(procIO,SIGNAL(processExited(KProcess*)),
-            this,SLOT(procIO_processExited()));
-    connect(procIO,SIGNAL(readReady(KProcIO*)),this,SLOT(procIO_readReady()));
-    if (!procIO->start()) {
-      KMessageBox::error(parentWidget,"Could not run assistant.\n"
-                         "This feature requires Qt 3 Assistant.");
-      delete procIO;
-      procIO=static_cast<KProcIO *>(NULL);
-      return;
-    }
-  } else if (!page.isNull()) {
-    // Wait for Qt Assistant to actually open.
-    while (procIO && !socket) {
-      usleep(10000);
-      QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,10);
-    }
-    if (!procIO) goto start_new;
-    Q3TextStream stream(static_cast<QIODevice *>(socket));
-    stream<<page<<'\n';
-  }
-}
-
-void AssistantClient::procIO_processExited()
-{
-  disconnect(procIO,SIGNAL(processExited(KProcess*)),
-             this,SLOT(procIO_processExited()));
-  disconnect(procIO,SIGNAL(readReady(KProcIO*)),this,SLOT(procIO_readReady()));
-  procIO->deleteLater();
-  procIO=static_cast<KProcIO *>(NULL);
-  int socketStatus=socket?socket->socketStatus():0;
-  if (socketStatus && socketStatus<KExtendedSocket::lookupInProgress) {
-    KMessageBox::error(parentWidget,socket->strError(socketStatus,
-                                                     socket->systemError()),
-                       "Socket Error");
-  }
-  if (socket) delete socket;
-  socket=static_cast<KExtendedSocket *>(NULL);
-}
-
-void AssistantClient::procIO_readReady()
-{
-  QString line;
-  while (procIO->readln(line)>=0) {
-    if (!socket) {
-      bool ok;
-      unsigned short port=line.toUShort(&ok);
-      if (ok) {
-        socket=new KExtendedSocket("localhost",port,KExtendedSocket::inetSocket);
-        switch (socket->connect()) {
-          case 0:
-            break;
-          case -1:
-            KMessageBox::error(parentWidget,socket->strError(socket->socketStatus(),
-                                                             socket->systemError()),
-                               "Socket Error");
-            goto error;
-          case -2:
-            KMessageBox::error(parentWidget,"Failed to connect to Qt Assistant.",
-                               "Socket Error");
-            goto error;
-          case -3:
-            KMessageBox::error(parentWidget,"Connection to Qt Assistant timed out.",
-                               "Socket Error");
-            goto error;
-          default:
-            KMessageBox::error(parentWidget,"Socket Error.");
-            error:
-            disconnect(procIO,SIGNAL(processExited(KProcess*)),
-                       this,SLOT(procIO_processExited()));
-            disconnect(procIO,SIGNAL(readReady(KProcIO*)),
-                       this,SLOT(procIO_readReady()));
-            procIO->kill();
-            usleep(100000);
-            procIO->deleteLater();
-            procIO=static_cast<KProcIO *>(NULL);
-            delete socket;
-            socket=static_cast<KExtendedSocket *>(NULL);
-            return;
-        }
-        continue;
-      }
-    }
-    KMessageBox::error(parentWidget,line,"Qt Assistant Error");
-  }
-}

+ 0 - 46
ktigcc/assistant.h

@@ -1,46 +0,0 @@
-/*
-   ktigcc - TIGCC IDE for KDE
-
-   Copyright (C) 2006-2007 Kevin Kofler
-
-   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, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
-*/
-
-#pragma once
-
-#include <qobject.h>
-#include <qstring.h>
-
-class QWidget;
-class KProcIO;
-class KExtendedSocket;
-class AssistantClient : public QObject {
-  Q_OBJECT
-
-  public:
-    AssistantClient(QObject *parent=0, const QString &profile=QString::null);
-    ~AssistantClient();
-    void openAssistant(const QString &page=QString::null);
-
-  private slots:
-    void procIO_processExited();
-    void procIO_readReady();
-
-  private:
-    QWidget *parentWidget;
-    KProcIO *procIO;
-    KExtendedSocket *socket;
-    QString assistantProfile;
-};

+ 2 - 2
ktigcc/ktigcc.h

@@ -27,7 +27,7 @@
 #include <kaboutdata.h>
 #include <qstring.h>
 #include <q3valuevector.h>
-class AssistantClient;
+class QAssistantClient;
 class QClipboard;
 class SourceFile;
 typedef struct tprsettings tprSettings;
@@ -47,7 +47,7 @@ const char *lookup_doc_keyword(const char *keyword);
 extern KSharedConfigPtr pconfig;
 extern KAboutData *pabout;
 extern const char *parg;
-extern AssistantClient *assistant;
+extern QAssistantClient *assistant;
 extern QClipboard *clipboard;
 extern QStringList findHistory, replacementHistory;
 extern Q3PtrList<SourceFile> sourceFiles;

+ 1 - 3
ktigcc/ktigcc.pro

@@ -1,7 +1,7 @@
 TEMPLATE	= app
 LANGUAGE	= C++
 
-CONFIG	+= qt warn_on debug dbus
+CONFIG	+= qt warn_on debug dbus assistant
 
 QT += xml qt3support
 
@@ -17,7 +17,6 @@ HEADERS	+= tpr.h \
 	parsing.h \
 	colorlistitem.h \
 	completion.h \
-	assistant.h \
 	srcfilewin.h \
 	projectoptions.h \
 	programoptions.h \
@@ -41,7 +40,6 @@ SOURCES	+= ktigcc.cpp \
 	callbacks.cpp \
 	parsing.cpp \
 	completion.cpp \
-	assistant.cpp \
 	srcfilewin.cpp \
 	projectoptions.cpp \
 	programoptions.cpp \

+ 10 - 6
ktigcc/mainform.cpp

@@ -64,6 +64,7 @@
 #include <QPixmap>
 #include <QMouseEvent>
 #include <QCloseEvent>
+#include <QAssistantClient>
 #include <kapplication.h>
 #include <kparts/factory.h>
 #include <klibloader.h>
@@ -116,7 +117,6 @@
 #include "toolsdlg.h"
 #include "newsdlg.h"
 #include "completion.h"
-#include "assistant.h"
 
 using std::puts;
 using std::exit;
@@ -410,7 +410,7 @@ static Q3DockWindow *errorListDock;
 static ErrorList *errorList;
 static unsigned errorCountTotal=0,errorCountErrors=0,errorCountWarnings=0;
 static QString programOutput;
-AssistantClient *assistant;
+QAssistantClient *assistant;
 static unsigned fileCount=0, hFileCount=0, cFileCount=0, sFileCount=0, asmFileCount=0, qllFileCount=0, oFileCount=0, aFileCount=0, txtFileCount=0, othFileCount=0;
 tprSettings settings;
 tprLibOpts libopts;
@@ -1063,8 +1063,10 @@ void MainForm::init()
   othFilesListItem=folderListItem;
   folderListItem->setText(0,"Other Files");
   khelpmenu=new KHelpMenu(this,pabout);
-  assistant=new AssistantClient(this,
-    QString("%1/doc/html/qt-assistant.adp").arg(tigcc_base));
+  assistant=new QAssistantClient("",this);
+  QStringList args(QString("-profile"));
+  args.append(QString("%1/doc/html/qt-assistant.adp").arg(tigcc_base));
+  assistant->setArguments(args);
   lastDirectory=QString("%1/tigcc-projects").arg(QDir::homePath());
   if (!QDir(lastDirectory).exists() && !QDir().mkdir(lastDirectory))
     lastDirectory=QString("%1/projects").arg(tigcc_base);
@@ -1308,8 +1310,10 @@ void MainForm::accel_activated(int index)
         if (wordUnderCursor.isEmpty()) return;
         QString docFile=lookup_doc_keyword(wordUnderCursor);
         if (docFile.isEmpty()) return;
-        assistant->openAssistant(
-          QString(tigcc_base)+QString("/doc/html/")+docFile);
+        // wait for Qt Assistant to actually open
+        while (!assistant->isOpen())
+          QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
+        assistant->showPage(QString(tigcc_base)+QString("/doc/html/")+docFile);
         break;
       }
       case 6:

+ 5 - 3
ktigcc/programoptions.cpp

@@ -29,9 +29,9 @@
 #include <qeventloop.h>
 #include <qtooltip.h>
 #include <QMouseEvent>
+#include <QAssistantClient>
 #include "ktigcc.h"
 #include "tpr.h"
-#include "assistant.h"
 
 void ProgramOptions::ImportSettings()
 {
@@ -304,8 +304,10 @@ void ProgramOptions::mousePressEvent( QMouseEvent * e )
     QString docFile=lookup_doc_keyword(toolTip);
     if (docFile.isEmpty()) return;
     force_qt_assistant_page(1);
-    assistant->openAssistant(
-      QString(tigcc_base)+QString("/doc/html/")+docFile);
+    // wait for Qt Assistant to actually open
+    while (!assistant->isOpen())
+      QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
+    assistant->showPage(QString(tigcc_base)+QString("/doc/html/")+docFile);
   }
 }
 

+ 5 - 3
ktigcc/srcfilewin.cpp

@@ -45,6 +45,7 @@
 #include <Q3PopupMenu>
 #include <QEvent>
 #include <QCloseEvent>
+#include <QAssistantClient>
 #include <kparts/factory.h>
 #include <klibloader.h>
 #include <kate/document.h>
@@ -75,7 +76,6 @@
 #include "srcfile.h"
 #include "functions.h"
 #include "completion.h"
-#include "assistant.h"
 
 using std::puts;
 using std::exit;
@@ -353,8 +353,10 @@ void SourceFileWindow::accel_activated(int index)
         if (wordUnderCursor.isEmpty()) return;
         QString docFile=lookup_doc_keyword(wordUnderCursor);
         if (docFile.isEmpty()) return;
-        assistant->openAssistant(
-          QString(tigcc_base)+QString("/doc/html/")+docFile);
+        // wait for Qt Assistant to actually open
+        while (!assistant->isOpen())
+          QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
+        assistant->showPage(QString(tigcc_base)+QString("/doc/html/")+docFile);
         break;
       }
       case 6: