main.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 448 行 · 第 1/2 页
CPP
448 行
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt Assistant of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "mainwindow.h"#include "helpdialog.h"#include "config.h"#include <QTcpServer>#include <QTcpSocket>#include <QApplication>#include <QPixmap>#include <QStringList>#include <QDir>#include <QMessageBox>#include <QPointer>#include <QTranslator>#include <QLibraryInfo>#include <QLocale>#include <stdlib.h>#include <stdio.h>#if defined(USE_STATIC_JPEG_PLUGIN) #include <QtPlugin> Q_IMPORT_PLUGIN(qjpeg)#endif#define INDEX_CHECK( text ) if( i+1 >= argc ) { fprintf(stderr, "%s\n", text); return 1; }#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX)#include <QtDBus/QDBusConnection>#include <QtDBus/QDBusAbstractAdaptor>#include <QtDBus/QDBusObjectPath>#include "tabbedbrowser.h"class HelpWindowAdaptor : public QDBusAbstractAdaptor{ Q_OBJECT Q_CLASSINFO("D-Bus Interface", "com.trolltech.Assistant.HelpWindow") Q_PROPERTY(QString source READ source WRITE setSource)public: HelpWindowAdaptor(HelpWindow *w) : QDBusAbstractAdaptor(w), helpWindow(w) { setAutoRelaySignals(true); }public Q_SLOTS: inline QString source() const { return helpWindow->source().toString(); } inline void setSource(const QString &src) { helpWindow->setSource(src); } inline void clearHistory() { helpWindow->clearHistory(); } inline void backward() { helpWindow->backward(); } inline void forward() { helpWindow->forward(); } inline void reload() { helpWindow->reload(); } inline void home() { helpWindow->home(); }private: HelpWindow *helpWindow;};class AssistantAdaptor : public QDBusAbstractAdaptor{ Q_OBJECT Q_CLASSINFO("D-Bus Interface", "com.trolltech.Assistant.HelpViewer")public: AssistantAdaptor(MainWindow *mw) : QDBusAbstractAdaptor(mw), mw(mw) { QDBusConnection connection = QDBusConnection::sessionBus(); connection.registerService(QLatin1String("com.trolltech.Assistant")); connection.registerObject(QLatin1String("/Assistant"), mw); }public slots: void showLink(const QString &link) { mw->showLink(link); } QDBusObjectPath createNewTab(); QDBusObjectPath currentTab();private: QDBusObjectPath pathForBrowser(HelpWindow *window); MainWindow *mw;};QDBusObjectPath AssistantAdaptor::createNewTab(){ HelpWindow *window = mw->browsers()->newBackgroundTab(); return pathForBrowser(window);}QDBusObjectPath AssistantAdaptor::currentTab(){ HelpWindow *window = mw->browsers()->currentBrowser(); return pathForBrowser(window);}QDBusObjectPath AssistantAdaptor::pathForBrowser(HelpWindow *window){ int index = mw->browsers()->browsers().indexOf(window); if (index == -1) return QDBusObjectPath(); QString name(QLatin1String("/Assistant/Tabs/")); name += QString::number(index); QDBusObjectPath path(name); if (!window->findChild<HelpWindowAdaptor *>()) { (void)new HelpWindowAdaptor(window); QDBusConnection::sessionBus().registerObject(name, window); } return path;}#endif // QT_NO_DBUSclass AssistantSocket : public QTcpSocket{ Q_OBJECTpublic: AssistantSocket( int sock, QObject *parent = 0 ); ~AssistantSocket() {}signals: void showLinkRequest( const QString& );private slots: void readClient(); void connectionClosed();};class AssistantServer : public QTcpServer{ Q_OBJECTpublic: AssistantServer( QObject* parent = 0 ); quint16 getPort() const;signals: void showLinkRequest( const QString& ); void newConnect();public slots: virtual void incomingConnection( int socket );private: quint16 p;};AssistantSocket::AssistantSocket( int sock, QObject *parent ) : QTcpSocket( parent ){ connect( this, SIGNAL(readyRead()), SLOT(readClient()) ); connect( this, SIGNAL(disconnected()), SLOT(connectionClosed()) ); setSocketDescriptor( sock );}void AssistantSocket::readClient(){ QString link = QString(); while ( canReadLine() ) link = QLatin1String(readLine()); if ( !link.isNull() ) { link = link.replace(QLatin1String("\n"), QLatin1String("")); link = link.replace(QLatin1String("\r"), QLatin1String("")); QFileInfo fi(link); link = fi.absoluteFilePath(); emit showLinkRequest( link ); }}void AssistantSocket::connectionClosed(){ deleteLater();}AssistantServer::AssistantServer( QObject *parent ) : QTcpServer( parent ){ listen(QHostAddress::LocalHost, 0); if ( !isListening() ) { QMessageBox::critical( 0, tr( "Qt Assistant" ), tr( "Failed to bind to port %1" ).arg( serverPort() ) ); exit( 1 ); } p = serverPort();}quint16 AssistantServer::getPort() const
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?