Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

calc.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include <qvaluelist.h>
00022 #include <qpe/qpeapplication.h>
00023 #include <qdir.h>
00024 #include <qwidgetstack.h>
00025 
00026 #include "calc.h"
00027 #include "plugininterface.h"
00028 
00029 calc::calc (QWidget * p, const char *n):QWidget (p, n)
00030 {
00031   setCaption (tr ("Calculator"));
00032 
00033 // widgets
00034   LCD = new QLCDNumber (this);
00035   LCD->setMaximumSize (QSize (240, 30));
00036     LCD->setNumDigits(12);
00037 LCD->setSegmentStyle(QLCDNumber::Filled);
00038   pluginWidgetStack = new QWidgetStack (this);
00039 
00040 // layout widgets
00041   calculatorLayout = new QVBoxLayout (this);
00042   calculatorLayout->addWidget (LCD);
00043   calculatorLayout->addWidget (pluginWidgetStack);
00044 
00045 // no formatting of display for now
00046   connect (&engine, SIGNAL(display(double)), LCD, SLOT(display(double)));
00047   connect (&engine, SIGNAL(display(const QString&)), LCD, SLOT(display(const QString&)));
00048     connect (&engine, SIGNAL(setBinMode()), LCD, SLOT(setBinMode()));
00049     connect (&engine, SIGNAL(setOctMode()), LCD, SLOT(setOctMode()));
00050     connect (&engine, SIGNAL(setDecMode()), LCD, SLOT(setDecMode()));
00051     connect (&engine, SIGNAL(setHexMode()), LCD, SLOT(setHexMode()));
00052 
00053 #ifndef NO_PLUGINS
00054 // load plugins
00055   QValueList < Plugin >::Iterator mit;
00056   for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) {
00057     (*mit).interface->release ();
00058     (*mit).library->unload ();
00059     delete (*mit).library;
00060   }
00061   pluginList.clear ();
00062 
00063   QString path = QPEApplication::qpeDir() + "plugins/calculator";
00064   QDir dir (path, "lib*.so");
00065   QStringList list = dir.entryList ();
00066 
00067   QStringList::Iterator it;
00068   for (it = list.begin (); it != list.end (); ++it) {
00069     CalcInterface *iface = 0;
00070     QLibrary *lib = new QLibrary (path + "/" + *it);
00071     Plugin plugin;
00072     plugin.pluginWidget = 0;
00073 
00074     if (lib->queryInterface (IID_Calc, (QUnknownInterface **) & iface) ==
00075         QS_OK) {
00076       plugin.library = lib;
00077       plugin.interface = iface;
00078       plugin.pluginWidget = plugin.interface->getPlugin(&engine,pluginWidgetStack);
00079       if (plugin.pluginWidget) 
00080         pluginWidgetStack->addWidget (plugin.pluginWidget, pluginList.count());
00081       pluginList.append (plugin);
00082     } else {
00083       delete lib;
00084     }
00085   }
00086   setMode (1);
00087 #else
00088 // load simple interface
00089 #endif
00090 }
00091 
00092 calc::~calc ()
00093 {
00094 #ifndef NO_PLUGINS
00095   QValueList < Plugin >::Iterator mit;
00096   for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) {
00097     (*mit).interface->release ();
00098     (*mit).library->unload ();
00099     delete (*mit).library;
00100   }
00101 #endif
00102 }
00103 

Generated on Sat Nov 5 16:18:01 2005 for OPIE by  doxygen 1.4.2