kexi
kexiappmainwindow.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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 this->addFunction0<Kross::Api::Variant>("isConnected", this, &KexiAppMainWindow::isConnected);
00059 this->addFunction0<Kross::Api::Object>("getConnection", this, &KexiAppMainWindow::getConnection);
00060
00061 this->addFunction1<Kross::Api::List, Kross::Api::Variant>("getPartItems", this, &KexiAppMainWindow::getPartItems);
00062 this->addFunction1<Kross::Api::Variant, KexiAppPartItem>("openPartItem", this, &KexiAppMainWindow::openPartItem);
00063 }
00064
00065 KexiAppMainWindow::~KexiAppMainWindow()
00066 {
00067 delete d;
00068 }
00069
00070 const QString KexiAppMainWindow::getClassName() const
00071 {
00072 return "Kross::KexiApp::KexiAppMainWindow";
00073 }
00074
00075 bool KexiAppMainWindow::isConnected()
00076 {
00077 return d->project()->isConnected();
00078 }
00079
00080 Kross::Api::Object::Ptr KexiAppMainWindow::getConnection()
00081 {
00082 ::KexiDB::Connection* connection = d->project()->dbConnection();
00083 if(! connection)
00084 throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("No connection established.") );
00085 Kross::Api::Module::Ptr module = Kross::Api::Manager::scriptManager()->loadModule("krosskexidb");
00086 if(! module)
00087 throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("Could not load \"krosskexidb\" module.") );
00088 return module->get("KexiDBConnection", connection);
00089 }
00090
00091 Kross::Api::List* KexiAppMainWindow::getPartItems(const QString& mimetype)
00092 {
00093 if(mimetype.isNull()) return 0;
00094 KexiPart::ItemDict* items = d->project()->itemsForMimeType( mimetype.latin1() );
00095 if(! items) return 0;
00096 return new Kross::Api::ListT<KexiAppPartItem>( *items );
00097 }
00098
00099 bool KexiAppMainWindow::openPartItem(KexiAppPartItem* partitem)
00100 {
00101 bool openingCancelled;
00102 KexiDialogBase* dialog = partitem
00103 ? d->mainwindow->openObject(partitem->item(), Kexi::DataViewMode, openingCancelled)
00104 : 0;
00105 return (dialog != 0 && ! openingCancelled);
00106 }
|