Example #1
0
void SyncTaskListItem::openPopup()
{
    bool preferedFound = false;
    offers = getOffers();
    KTrader::OfferList::ConstIterator it;

    itemMenu.clear();
    itemMenu.setCaption(i18n("Services for") + " " + text());

    itemMenu.insertTitle(i18n("Services for") + " " + text());
    itemMenu.setCheckable(true);

    itemMenu.setEnabled(true);

    if (offers.begin() != offers.end()) {
        for (it = offers.begin(); it != offers.end(); ++it) {
            KService::Ptr service = *it;
            kdDebug(2120) << i18n("Open Name:") << " "
              << service->name() << "; " << i18n("Library:") << " "
              << service->library() << endl;
            int item = itemMenu.insertItem(service->name());
            if (service->name() == preferedOfferTemp) {
                itemMenu.setItemChecked(item, true);
                preferedFound = true;
            }
        }

        if (!preferedFound) {
            preferedOffer = "";
            preferedLibrary = "";
        }

        itemMenu.move(-1000,-1000);
        itemMenu.show();
        itemMenu.hide();

        QPoint g = QCursor::pos();

        if (itemMenu.height() < g.y()) {
            itemMenu.popup(QPoint( g.x(), g.y() - itemMenu.height()));
        } else {
            itemMenu.popup(QPoint(g.x(), g.y()));
        }
    }
}
Example #2
0
KonqViewFactory KonqFactory::createView( const QString &serviceType,
                                         const QString &serviceName,
                                         KService::Ptr *serviceImpl,
                                         KService::List *partServiceOffers,
                                         KService::List *appServiceOffers,
					 bool forceAutoEmbed )
{
  kDebug() << "Trying to create view for" << serviceType << serviceName;

  // We need to get those in any case
  KService::List offers, appOffers;

  // Query the trader
  getOffers( serviceType, &offers, &appOffers );

  if ( partServiceOffers )
     (*partServiceOffers) = offers;
  if ( appServiceOffers )
     (*appServiceOffers) = appOffers;

  // We ask ourselves whether to do it or not only if no service was specified.
  // If it was (from the View menu or from RMB + Embedding service), just do it.
  forceAutoEmbed = forceAutoEmbed || !serviceName.isEmpty();
  // Or if we have no associated app anyway, then embed.
  forceAutoEmbed = forceAutoEmbed || ( appOffers.isEmpty() && !offers.isEmpty() );
  // Or if the associated app is konqueror itself, then embed.
  if ( !appOffers.isEmpty() )
    forceAutoEmbed = forceAutoEmbed || KonqMainWindow::isMimeTypeAssociatedWithSelf( serviceType, appOffers.first() );

  if ( ! forceAutoEmbed )
  {
    if ( ! KonqFMSettings::settings()->shouldEmbed( serviceType ) )
    {
      kDebug() << "KonqFMSettings says: don't embed this servicetype";
      return KonqViewFactory();
    }
  }

    KService::Ptr service;

    // Look for this service
    if (!serviceName.isEmpty()) {
        KService::List::const_iterator it = offers.constBegin();
        for ( ; it != offers.constEnd() && !service ; ++it ) {
            if ( (*it)->desktopEntryName() == serviceName ) {
                kDebug() << "Found requested service" << serviceName;
                service = *it;
            }
        }
    }

    KonqViewFactory viewFactory;
    if (service) {
        kDebug() << "Trying to open lib for requested service " << service->desktopEntryName();
        viewFactory = tryLoadingService(service);
        // If this fails, then return an error.
        // When looking for konq_sidebartng or konq_aboutpage, we don't want to end up
        // with khtml or another Browser/View part in case of an error...
    } else {
        KService::List::Iterator it = offers.begin();
        for ( ; viewFactory.isNull() /* exit as soon as we get one */ && it != offers.end() ; ++it ) {
            service = (*it);
            // Allowed as default ?
            QVariant prop = service->property( "X-KDE-BrowserView-AllowAsDefault" );
            kDebug() << service->desktopEntryName() << " : X-KDE-BrowserView-AllowAsDefault is valid : " << prop.isValid();
            if ( !prop.isValid() || prop.toBool() ) { // defaults to true
                //kDebug() << "Trying to open lib for service " << service->name();
                viewFactory = tryLoadingService(service);
                // If this works, we exit the loop.
            } else {
                kDebug() << "Not allowed as default " << service->desktopEntryName();
            }
        }
    }

    if (serviceImpl)
        (*serviceImpl) = service;

    if (viewFactory.isNull()) {
        if (offers.isEmpty())
            kWarning() << "no part was associated with" << serviceType;
        else
            kWarning() << "no part could be loaded"; // full error was shown to user already
        return viewFactory;
    }

    QVariantList args;
    const QVariant prop = service->property( "X-KDE-BrowserView-Args" );
    if (prop.isValid()) {
        Q_FOREACH(const QString& str, prop.toString().split(' '))
            args << QVariant(str);
    }
Example #3
0
int SyncTaskListItem::createSyncPlugin(bool state)
{
    int ret = 0;

    if (syncPlugin != NULL) {
        syncPlugin->unInit();
        delete syncPlugin;
        syncPlugin = NULL;
    }

    if (state) {
        KTrader::OfferList offers;

        QString library = getPreferedLibrary();
        QString offer = getPreferedOffer();

        if (library.isEmpty()) {
            offers = getOffers();
            if (offers.begin() != offers.end()) {
                KService::Ptr service = *offers.begin();
                library = service->library();
                offer = service->name();
            }
        }

        if (!library.isEmpty()) {
            kdDebug(2120) << i18n("Name:") << " " << offer << "; "
            << i18n("Library:") << " " << library << endl;
            KLibFactory *factory = KLibLoader::self()->factory(library.ascii());
            if (!factory) {
                QString errorMessage = KLibLoader::self()->lastErrorMessage();
                kdDebug(2120) << i18n("There was an error:") << " " << offer << errorMessage <<
                    endl;
                ret = ERROR_NOFACTORY;
            } else {
                if (factory->inherits("RakiSyncFactory")) {
                    RakiSyncFactory *syncFactory =
                        static_cast<RakiSyncFactory*> (factory);
                    syncPlugin = static_cast<RakiSyncPlugin*>
                                 (syncFactory->create());
                    syncPlugin->init(rra, this, pdaName, this->listView(), offer);
                    syncFactory->callme(); // Fake call to link correct.
                } else {
                    kdDebug(2120) << i18n("Library no Raki-Plugin") << endl;
                    ret = ERROR_WRONGLIBRARYTYPE;
                }
            }
        } else {
            ret = ERROR_NOSYNCHRONIZER;
        }
    }

    switch(ret) {
    case ERROR_NOSYNCHRONIZER:
        KMessageBox::information(this->listView(), "<p>" + i18n("No Synchronizer found for") + " <b>" +
                QString(rra->getTypeForId(objectType)->name2) + "</b></p>", QString(rra->getTypeForId(objectType)->name2) + pdaName);
        this->setOn(false);
        this->makePersistent();
        break;
    case ERROR_WRONGLIBRARYTYPE:
        KMessageBox::error(this->listView(), "<p>" + i18n("Wrong library type for") +" <b>" +
                QString(rra->getTypeForId(objectType)->name2) + "</b></p>", QString(rra->getTypeForId(objectType)->name2) + pdaName);
        this->setOn(false);
        this->makePersistent();
        break;
    case ERROR_NOFACTORY:
        KMessageBox::error(this->listView(), "<p>" + i18n("Wrong library type for") + " <b>" +
                QString(rra->getTypeForId(objectType)->name2) + "</b></p>", QString(rra->getTypeForId(objectType)->name2) + pdaName);
        this->setOn(false);
        this->makePersistent();
        break;
    }

    return ret;
}