void KexiFormEventAction::slotTrigger()
{
    kDebug() << d->actionName << d->objectName;
    KexiProject* project = KexiMainWindowIface::global()->project();
    if (!project)
        return;
    KexiPart::Part* part = Kexi::partManager().partForClass(
                               QString("org.kexi-project.%1").arg(d->actionName));
    if (!part)
        return;
    KexiPart::Item* item = project->item(part->info(), d->objectName);
    if (!item)
        return;
    bool actionCancelled = false;
    if (d->actionOption.isEmpty()) { // backward compatibility (good defaults)
        if (part->info()->isExecuteSupported())
            part->execute(item, parent());
        else
            KexiMainWindowIface::global()->openObject(item, Kexi::DataViewMode, actionCancelled);
    } else {
//! @todo react on failure...
        if (d->actionOption == "open")
            KexiMainWindowIface::global()->openObject(item, Kexi::DataViewMode, actionCancelled);
        else if (d->actionOption == "execute")
            part->execute(item, parent());
        else if (d->actionOption == "print") {
            if (part->info()->isPrintingSupported())
                KexiMainWindowIface::global()->printItem(item);
        }
#ifndef KEXI_NO_QUICK_PRINTING
        else if (d->actionOption == "printPreview") {
            if (part->info()->isPrintingSupported())
                KexiMainWindowIface::global()->printPreviewForItem(item);
        }
        else if (d->actionOption == "pageSetup") {
            if (part->info()->isPrintingSupported())
                KexiMainWindowIface::global()->showPageSetupForItem(item);
        }
#endif
        else if (d->actionOption == "exportToCSV"
                   || d->actionOption == "copyToClipboardAsCSV") {
            if (part->info()->isDataExportSupported())
                KexiMainWindowIface::global()->executeCustomActionForObject(item, d->actionOption);
        } else if (d->actionOption == "new")
            KexiMainWindowIface::global()->newObject(part->info(), actionCancelled);
        else if (d->actionOption == "design")
            KexiMainWindowIface::global()->openObject(item, Kexi::DesignViewMode, actionCancelled);
        else if (d->actionOption == "editText")
            KexiMainWindowIface::global()->openObject(item, Kexi::TextViewMode, actionCancelled);
        else if (d->actionOption == "close") {
            tristate res = KexiMainWindowIface::global()->closeObject(item);
            if (~res)
                actionCancelled = true;
        }
    }
}
Exemplo n.º 2
0
    bool setupSchemaObject(KDbObject *object, KexiPart::Item *item,
                           KexiView::StoreNewDataOptions options) const
    {
        object->setName(item->name());
        object->setCaption(item->caption());
        object->setDescription(item->description());

        KexiProject *project = KexiMainWindowIface::global()->project();
        KexiPart::Item* existingItem = project->item(part->info(), object->name());
        if (existingItem && !(options & KexiView::OverwriteExistingData)) {
            KMessageBox::information(win,
                                     xi18n("Could not create new object.")
                                     + win->part()->i18nMessage("Object <resource>%1</resource> already exists.", win)
                                       .subs(object->name()).toString());
            return false;
        }
        return true;
    }
Exemplo n.º 3
0
tristate KexiWindow::storeDataAs(KexiPart::Item *item, KexiView::StoreNewDataOptions options)
{
    if (neverSaved()) {
        kWarning() << "The data was never saved, so storeNewData() should be called instead, giving up.";
        return false;
    }
    KexiView *v = selectedView();
    if (!v) {
        return false;
    }
    //create schema object and assign information
    KexiProject *project = KexiMainWindowIface::global()->project();
    KexiDB::SchemaData sdata(project->idForClass(d->part->info()->partClass()));
    if (!d->setupSchemaData(&sdata, item, options)) {
        return false;
    }

    bool cancel = false;
    KexiDB::SchemaData *newSchemaData;
    if (isDirty()) { // full save of new data
        newSchemaData = v->storeNewData(sdata, options, cancel);
    }
    else { // there were no changes; full copy of the data is enough
           // - gives better performance (e.g. tables are copied on server side)
           // - works without bothering the user (no unnecessary questions)
        newSchemaData = v->copyData(sdata, options, cancel);
    }

    if (cancel) {
        return cancelled;
    }
    if (!newSchemaData) {
        setStatus(project->dbConnection(), i18n("Saving object's definition failed."), "");
        return false;
    }
    setSchemaData(newSchemaData); // deletes previous schema if owned

    if (project->idForClass(part()->info()->partClass()) < 0) {
        if (!project->createIdForPart(*part()->info()))
            return false;
    }
    // for now this Window has new item assigned
    d->item = item;

    // new schema data has now ID updated to a unique value
    // -assign that to item's identifier
    item->setIdentifier(d->schemaData->id());

    project->addStoredItem(part()->info(), d->item);

    // set 'dirty' flag on every dialog's view
    setDirty(false);

    return true;
}
Exemplo n.º 4
0
tristate KexiWindow::storeNewData(KexiView::StoreNewDataOptions options)
{
    if (!neverSaved()) {
        return false;
    }
    if (d->schemaData) {
        return false; //schema must not exist
    }
    KexiView *v = selectedView();
    if (!v) {
        return false;
    }
    //create schema object and assign information
    KexiProject *project = KexiMainWindowIface::global()->project();
    KexiDB::SchemaData sdata(project->idForClass(d->part->info()->partClass()));
    if (!d->setupSchemaData(&sdata, d->item, options)) {
        return false;
    }

    bool cancel = false;
    d->schemaData = v->storeNewData(sdata, options, cancel);
    if (cancel)
        return cancelled;
    if (!d->schemaData) {
        setStatus(project->dbConnection(), i18n("Saving object's definition failed."), "");
        return false;
    }

    if (project->idForClass(part()->info()->partClass()) < 0) {
        if (!project->createIdForPart(*part()->info()))
            return false;
    }
    /* Sets 'dirty' flag on every dialog's view. */
    setDirty(false);
    //new schema data has now ID updated to a unique value
    //-assign that to item's identifier
    d->item->setIdentifier(d->schemaData->id());
    project->addStoredItem(part()->info(), d->item);

    return true;
}
Exemplo n.º 5
0
KexiWindow* Part::openInstance(QWidget* parent, KexiPart::Item *item, Kexi::ViewMode viewMode,
                               QMap<QString, QVariant>* staticObjectArgs)
{
    Q_ASSERT(item);
    //now it's the time for creating instance actions
    if (!d->instanceActionsInitialized) {
        initInstanceActions();
        d->instanceActionsInitialized = true;
    }

    d->status.clearStatus();
    KexiWindow *window = new KexiWindow(parent,
                                        info()->supportedViewModes(), this, item);

    KexiProject *project = KexiMainWindowIface::global()->project();
    KDbObject object(project->typeIdForPluginId(info()->pluginId()));
    object.setName(item->name());
    object.setCaption(item->caption());
    object.setDescription(item->description());

    /*! @todo js: apply settings for caption displaying method; there can be option for
     - displaying item.caption() as caption, if not empty, without instanceName
     - displaying the same as above in tabCaption (or not) */
    window->setId(item->identifier()); //not needed, but we did it
    window->setWindowIcon(QIcon::fromTheme(window->iconName()));
    KexiWindowData *windowData = createWindowData(window);
    if (!windowData) {
        d->status = Kexi::ObjectStatus(KexiMainWindowIface::global()->project()->dbConnection(),
                                       xi18n("Could not create object's window."), xi18n("The plugin or object definition may be corrupted."));
        delete window;
        return 0;
    }
    window->setData(windowData);

    if (!item->neverSaved()) {
        //we have to load object data for this dialog
        loadAndSetSchemaObject(window, object, viewMode);
        if (!window->schemaObject()) {
            //last chance:
            if (false == d->askForOpeningInTextMode(
                        window, item, window->supportedViewModes(), viewMode)) {
                delete window;
                return 0;
            }
            viewMode = Kexi::TextViewMode;
            loadAndSetSchemaObject(window, object, viewMode);
        }
        if (!window->schemaObject()) {
            if (!d->status.error())
                d->status = Kexi::ObjectStatus(KexiMainWindowIface::global()->project()->dbConnection(),
                                               xi18n("Could not load object's definition."), xi18n("Object design may be corrupted."));
            d->status.append(
                Kexi::ObjectStatus(xi18n("You can delete \"%1\" object and create it again.",
                                        item->name()), QString()));

            window->close();
            delete window;
            return 0;
        }
    }

    bool switchingFailed = false;
    bool dummy;
    tristate res = window->switchToViewMode(viewMode, staticObjectArgs, &dummy);
    if (!res) {
        tristate askForOpeningInTextModeRes
        = d->askForOpeningInTextMode(window, item, window->supportedViewModes(), viewMode);
        if (true == askForOpeningInTextModeRes) {
            delete window->schemaObject(); //old one
            window->close();
            delete window;
            //try in text mode
            return openInstance(parent, item, Kexi::TextViewMode, staticObjectArgs);
        } else if (false == askForOpeningInTextModeRes) {
            delete window->schemaObject(); //old one
            window->close();
            delete window;
            qWarning() << "!window, cannot switch to a view mode" <<
                Kexi::nameForViewMode(viewMode);
            return 0;
        }
        //the window has an error info
        switchingFailed = true;
    }
    if (~res)
        switchingFailed = true;

    if (switchingFailed) {
        d->status = window->status();
        window->close();
        delete window;
        qWarning() << "!window, switching to view mode failed, " <<
            Kexi::nameForViewMode(viewMode);
        return 0;
    }
    window->registerWindow(); //ok?
    window->show();

    window->setMinimumSize(window->minimumSizeHint().width(), window->minimumSizeHint().height());

    //dirty only if it's a new object
    if (window->selectedView()) {
        window->selectedView()->setDirty(
            internalPropertyValue("newObjectsAreDirty", false).toBool() ? item->neverSaved() : false);
    }
    return window;
}
Exemplo n.º 6
0
KexiWindow* Part::openInstance(QWidget* parent, KexiPart::Item &item, Kexi::ViewMode viewMode,
                               QMap<QString, QVariant>* staticObjectArgs)
{
    //now it's the time for creating instance actions
    if (!d->instanceActionsInitialized) {
        initInstanceActions();
        d->instanceActionsInitialized = true;
    }

    d->status.clearStatus();
    KexiWindow *window = new KexiWindow(parent,
                                        d->supportedViewModes, *this, item);

    KexiProject *project = KexiMainWindowIface::global()->project();
    KexiDB::SchemaData sdata(project->idForClass(d->info->partClass())); // d->info->projectPartID());
    sdata.setName(item.name());
    sdata.setCaption(item.caption());
    sdata.setDescription(item.description());

    /*! @todo js: apply settings for caption displaying method; there can be option for
     - displaying item.caption() as caption, if not empty, without instanceName
     - displaying the same as above in tabCaption (or not) */
    window->setId(item.identifier()); //not needed, but we did it
    window->setWindowIcon(SmallIcon(window->itemIcon()));
#ifdef __GNUC__
#warning todo
#else
#pragma WARNING( todo )
#endif
#if 0
    if (window->mdiParent())
        window->mdiParent()->setIcon(*window->icon());
#endif
// window->setWindowIcon( *window->icon() );
    KexiWindowData *windowData = createWindowData(window);
    if (!windowData) {
        d->status = Kexi::ObjectStatus(KexiMainWindowIface::global()->project()->dbConnection(),
                                       i18n("Could not create object's window."), i18n("The plugin or object definition may be corrupted."));
        delete window;
        return 0;
    }
    window->setData(windowData);

    if (!item.neverSaved()) {
        //we have to load schema data for this dialog
        window->setSchemaData(loadSchemaData(window, sdata, viewMode));
        if (!window->schemaData()) {
            //last chance:
            if (false == d->askForOpeningInTextMode(
                        window, item, window->supportedViewModes(), viewMode)) {
                delete window;
                return 0;
            }
            viewMode = Kexi::TextViewMode;
            window->setSchemaData(loadSchemaData(window, sdata, viewMode));
        }
        if (!window->schemaData()) {
            if (!d->status.error())
                d->status = Kexi::ObjectStatus(KexiMainWindowIface::global()->project()->dbConnection(),
                                               i18n("Could not load object's definition."), i18n("Object design may be corrupted."));
            d->status.append(
                Kexi::ObjectStatus(i18n("You can delete \"%1\" object and create it again.",
                                        item.name()), QString()));

            window->close();
            delete window;
            return 0;
        }
    }

    bool switchingFailed = false;
    bool dummy;
    tristate res = window->switchToViewMode(viewMode, staticObjectArgs, dummy);
    if (!res) {
        tristate askForOpeningInTextModeRes
        = d->askForOpeningInTextMode(window, item, window->supportedViewModes(), viewMode);
        if (true == askForOpeningInTextModeRes) {
            delete window->schemaData(); //old one
            window->close();
            delete window;
            //try in text mode
            return openInstance(parent, item, Kexi::TextViewMode, staticObjectArgs);
        } else if (false == askForOpeningInTextModeRes) {
            delete window->schemaData(); //old one
            window->close();
            delete window;
            kexiwarn << "Part::openInstance() !window, cannot switch to a view mode " <<
            Kexi::nameForViewMode(viewMode);
            return 0;
        }
        //the window has an error info
        switchingFailed = true;
    }
    if (~res)
        switchingFailed = true;

    if (switchingFailed) {
        d->status = window->status();
        window->close();
        delete window;
        kexiwarn << "Part::openInstance() !window, switching to view mode failed, " <<
        Kexi::nameForViewMode(viewMode);
        return 0;
    }
    window->registerWindow(); //ok?
    window->show();

#ifdef __GNUC__
#warning Part::openInstance(): resize window->resize(window->sizeHint()) for standalone windows
#else
#pragma WARNING( Part::openInstance(): resize window->resize(window->sizeHint()) for standalone windows )
#endif
#if 0
    if (window->mdiParent() && window->mdiParent()->state() == KexiMdiMainFrm::Normal) //only resize the window if it is in normal state
        window->resize(window->sizeHint());
#endif
    window->setMinimumSize(window->minimumSizeHint().width(), window->minimumSizeHint().height());

    //dirty only if it's a new object
    if (window->selectedView())
        window->selectedView()->setDirty(
            internalPropertyValue("newObjectsAreDirty", false).toBool() ? item.neverSaved() : false);

    kDebug() << "window returned.";
    return window;
}