Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}