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 addFunction("isConnected", &KexiAppMainWindow::isConnected);
00059 addFunction("getConnection", &KexiAppMainWindow::getConnection);
00060
00061 addFunction("getPartItems", &KexiAppMainWindow::getPartItems);
00062 addFunction("openPartItem", &KexiAppMainWindow::openPartItem);
00063
00064
00065
00066
00067
00068
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;
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
|