kexi

kexiappmainwindow.cpp

00001 /***************************************************************************
00002  * kexiappmainwindow.cpp
00003  * This file is part of the KDE project
00004  * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #include "kexiappmainwindow.h"
00021 #include "kexiapppart.h"
00022 
00023 #include "core/keximainwindow.h"
00024 #include "core/kexiproject.h"
00025 #include "core/kexi.h"
00026 #include "kexidb/connection.h"
00027 
00028 #include "main/manager.h"
00029 
00030 //#include <kdebug.h>
00031 
00032 namespace Kross { namespace KexiApp {
00033 
00035     class KexiAppMainWindowPrivate
00036     {
00037         public:
00038             KexiMainWindow* mainwindow;
00039 
00040             KexiProject* project() {
00041                 KexiProject* project = mainwindow->project();
00042                 if(! project)
00043                     throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("No project loaded.") );
00044                 return project;
00045             }
00046     };
00047 
00048 }}
00049 
00050 using namespace Kross::KexiApp;
00051 
00052 KexiAppMainWindow::KexiAppMainWindow(KexiMainWindow* mainwindow)
00053     : Kross::Api::Class<KexiAppMainWindow>("KexiAppMainWindow")
00054     , d(new KexiAppMainWindowPrivate())
00055 {
00056     d->mainwindow = mainwindow;
00057 
00058     addFunction("isConnected", &KexiAppMainWindow::isConnected);
00059     addFunction("getConnection", &KexiAppMainWindow::getConnection);
00060 
00061     addFunction("getPartItems", &KexiAppMainWindow::getPartItems);
00062     addFunction("openPartItem", &KexiAppMainWindow::openPartItem);
00063 
00064     //addFunction("hasObject", &KexiAppMainWindow::hasObject);
00065     //addFunction("getObject", &KexiAppMainWindow::getObject);
00066     //addFunction("getObjects", &KexiAppMainWindow::getObjects);
00067     //addFunction("openObject", &KexiAppMainWindow::openObject);
00068     //addFunction("hasObject", &KexiAppMainWindow::closeObject);
00069 }
00070 
00071 KexiAppMainWindow::~KexiAppMainWindow()
00072 {
00073     delete d;
00074 }
00075 
00076 const QString KexiAppMainWindow::getClassName() const
00077 {
00078     return "Kross::KexiApp::KexiAppMainWindow";
00079 }
00080 
00081 Kross::Api::Object::Ptr KexiAppMainWindow::isConnected(Kross::Api::List::Ptr)
00082 {
00083     return new Kross::Api::Variant( QVariant(d->project()->isConnected(), 0) );
00084 }
00085 
00086 Kross::Api::Object::Ptr KexiAppMainWindow::getConnection(Kross::Api::List::Ptr)
00087 {
00088     ::KexiDB::Connection* connection = d->project()->dbConnection();
00089     if(! connection)
00090         throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("No connection established.") );
00091     Kross::Api::Module::Ptr module = Kross::Api::Manager::scriptManager()->loadModule("krosskexidb");
00092     if(! module)
00093         throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("Could not load \"krosskexidb\" module.") );
00094     return module->get("KexiDBConnection", connection);
00095 }
00096 
00097 Kross::Api::Object::Ptr KexiAppMainWindow::getPartItems(Kross::Api::List::Ptr args)
00098 {
00099     QString mimetype = Kross::Api::Variant::toString(args->item(0));
00100     if(mimetype.isNull()) return 0; // just to be sure...
00101     KexiPart::ItemDict* items = d->project()->itemsForMimeType( mimetype.latin1() );
00102     if(! items) return 0;
00103     return new Kross::Api::ListT<Kross::KexiApp::KexiAppPartItem, ::KexiPart::Item>( *items );
00104 }
00105 
00106 Kross::Api::Object::Ptr KexiAppMainWindow::openPartItem(Kross::Api::List::Ptr args)
00107 {
00108     KexiAppPartItem* partitem = Kross::Api::Object::fromObject<KexiAppPartItem>(args->item(0));
00109     bool openingCancelled;
00110     KexiDialogBase* dialog = partitem ? d->mainwindow->openObject( partitem->item(),
00111         Kexi::DataViewMode, openingCancelled ) : 0;
00112     return new Kross::Api::Variant( QVariant(dialog != 0, 0) );
00113 }
00114 
KDE Home | KDE Accessibility Home | Description of Access Keys