Back to index

lightning-sunbird  0.9+nobinonly
plugin.cpp
Go to the documentation of this file.
00001 /* Version: MPL 1.1/GPL 2.0/LGPL 2.1
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Lixto GmbH.
00020  * Portions created by the Initial Developer are Copyright (C) 2004
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Michal Ceresna <ceresna@amos.sturak.sk>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include <dlfcn.h>
00041 
00042 #include <qdir.h>
00043 #include <qlabel.h>
00044 
00045 #include "qgeckoembed.h"
00046 #include "plugin.h"
00047 #include "plugin.xpm"
00048 
00049 QGeckoPlugin::QGeckoPlugin()
00050 {
00051 }
00052 
00053 QStringList QGeckoPlugin::keys() const
00054 {
00055     QStringList list;
00056     list << "QGeckoEmbed";
00057     return list;
00058 }
00059 
00060 QWidget* QGeckoPlugin::create(const QString& key,
00061                               QWidget* parent,
00062                               const char* name)
00063 {
00064     if (key=="QGeckoEmbed") {
00065         //nicer would be to use the QLibrary, but it uses only
00066         //the RTLD_LAZY flag and we need the RTLD_GLOBAL
00067         //to successfully load the rest of mozilla libs
00068         void *handle1 = dlopen("libxpcom.so", RTLD_NOW|RTLD_GLOBAL);
00069         void *handle2 = dlopen("libqgeckoembed.so", RTLD_NOW|RTLD_GLOBAL);
00070         if (!handle1 || !handle2) {
00071             QLabel *l = new QLabel(parent, name);
00072             l->setText("<html><body>"
00073                        "Unable to initialize Mozilla.<br>"
00074                        "Try to set <b>MOZILLA_FIVE_HOME</b> and "
00075 #ifdef Q_WS_WIN
00076                        "<b>PATH</b>"
00077 #else
00078                        "<b>LD_LIBRARY_PATH</b>"
00079 #endif
00080                        " variables before starting the Qt Designer."
00081                        "</body></html>");
00082             return l;
00083         }
00084         else {
00085             //this is a workaround for mozilla bug:
00086             //call to NS_InitEmbedding works only once
00087             static bool initialized = FALSE;
00088             if (!initialized) {
00089                 QGeckoEmbed::
00090                 initialize(QDir::
00091                            convertSeparators(QDir::home().absPath()+
00092                                              "/.qgeckoembed-qtdesigner"),
00093                            "QtDesigner");
00094                 //QGeckoGlobals::pushStartup()
00095                 static QGeckoEmbed *sentinel;
00096                 sentinel = new QGeckoEmbed(NULL, "sentinel");
00097                 initialized = TRUE;
00098             }
00099             QGeckoEmbed *me = new QGeckoEmbed(parent, name);
00100             me->loadURL("about:");
00101             return me;
00102         }
00103     }
00104     else {
00105         return NULL;
00106     }
00107 
00108 }
00109 
00110 QString QGeckoPlugin::includeFile(const QString& key) const
00111 {
00112     return
00113         key=="QGeckoEmbed"?
00114         "qgeckoembed.h":
00115         QString::null;
00116 }
00117 
00118 QString QGeckoPlugin::group(const QString& key) const
00119 {
00120     return
00121         key=="QGeckoEmbed"?
00122         "Display (Mozilla)":
00123         QString::null;
00124 }
00125 
00126 QIconSet QGeckoPlugin::iconSet(const QString&) const
00127 {
00128     return QIconSet(QPixmap(mozilla_pixmap));
00129 }
00130 
00131 QString QGeckoPlugin::toolTip(const QString& key) const
00132 {
00133     return
00134         key=="QGeckoEmbed"?
00135         "Mozilla Browser Control":
00136         QString::null;
00137 }
00138 
00139 QString QGeckoPlugin::whatsThis(const QString& key) const
00140 {
00141     return
00142         key=="QGeckoEmbed"?
00143         "A widget with Mozilla Web Browser":
00144         QString::null;
00145 }
00146 
00147 
00148 bool QGeckoPlugin::isContainer(const QString&) const
00149 {
00150     return FALSE;
00151 }
00152 
00153 Q_EXPORT_PLUGIN(QGeckoPlugin)
00154