void KexiMacroError::designbtnClicked() { if(! d->mainwin->project()) { kdWarning() << QString("KexiMacroError::designbtnClicked(): No project open.") << endl; return; } // We need to determinate the KexiPart::Item which should be opened. KSharedPtr<KoMacro::Macro> macro = d->context->macro(); const QString name = macro->name(); KexiPart::Item* item = d->mainwin->project()->itemForMimeType("kexi/macro", name); if(! item) { kdWarning() << QString("KexiMacroError::designbtnClicked(): No such macro \"%1\"").arg(name) << endl; return; } // Try to open the KexiPart::Item now. bool openingCancelled; if(! d->mainwin->openObject(item, Kexi::DesignViewMode, openingCancelled)) { if(! openingCancelled) { kdWarning() << QString("KexiMacroError::designbtnClicked(): Open macro \"%1\" in designview failed.").arg(name) << endl; return; } } close(); }
void MacroTests::testMacro() { kdDebug()<<"===================== testMacro() ======================" << endl; QDomElement const domelement = d->doomdocument->documentElement(); KSharedPtr<KoMacro::Macro> macro1 = KoMacro::Manager::self()->createMacro("testMacro"); KSharedPtr<KoMacro::Macro> macro2 = KoMacro::Manager::self()->createMacro("testMacro"); //Is our XML parseable ? KOMACROTEST_ASSERT(macro1->parseXML(domelement),true); KOMACROTEST_ASSERT(macro2->parseXML(domelement),true); //check that it is not null KOMACROTEST_XASSERT(sizetype(macro1.data()), sizetype(0)); KOMACROTEST_XASSERT(sizetype(macro2.data()), sizetype(0)); //check macro1 == macro2 KOMACROTEST_ASSERT(macro1->name(), macro2->name() ); //create list of KsharedPtr from the childs of the macro QValueList< KSharedPtr<KoMacro::MacroItem> >& items1 = macro1->items(); QValueList< KSharedPtr<KoMacro::MacroItem> >& items2 = macro2->items(); //check that there is one KOMACROTEST_XASSERT( items1.count(), sizetype(0) ); KOMACROTEST_XASSERT( items2.count(), sizetype(0) ); //check macro1 == macro2 KOMACROTEST_ASSERT( items1.count(), items2.count() ); //check the name KOMACROTEST_ASSERT( QString(macro1->name()), QString("testMacro") ); { const QString tmp1 = QString("test"); macro1->setName(tmp1); //check the name changed KOMACROTEST_XASSERT( QString(macro1->name()), QString("testMacro") ); //check the name KOMACROTEST_ASSERT( QString(macro1->name()), QString("test") ); } //fetch the first one KSharedPtr<KoMacro::Action> actionptr = items1[0]->action(); //check that it is not null KOMACROTEST_XASSERT(sizetype(actionptr.data()), sizetype(0)); //check that it has the right name KOMACROTEST_ASSERT( QString(actionptr->name()), QString("testaction") ); //check that it has the right text KOMACROTEST_ASSERT( actionptr->text(), QString("Test") ); //try to clear items macro1->clearItems(); //get items items1 = macro1->items(); //check that they are deleted KOMACROTEST_ASSERT( items1.count(), sizetype(0) ); }
void IpodPlaylistProvider::rename( Playlists::PlaylistPtr playlist, const QString &newName ) { if( !m_playlists.contains( playlist ) ) // make following static cast safe return; KSharedPtr<IpodPlaylist> ipodPlaylist = KSharedPtr<IpodPlaylist>::staticCast( playlist ); if( ipodPlaylist->type() != IpodPlaylist::Normal ) return; // special playlists cannot be renamed playlist->setName( newName ); emit updated(); emit startWriteDatabaseTimer(); }
void KSharedPtrTest::testDifferentTypes() { dtor_called = 0; { Derived* obj = new Derived; KSharedPtr<Base> ptrBase(obj); // then we call some method that takes a KSharedPtr<Base> as argument // and there we downcast again: KSharedPtr<Derived> ptrDerived = KSharedPtr<Derived>::staticCast( ptrBase ); QCOMPARE( dtor_called, 0 ); // no dtor called yet QCOMPARE( ptrDerived.data(), obj ); // now test assignment operator ptrDerived = KSharedPtr<Derived>::dynamicCast( ptrBase ); QCOMPARE( dtor_called, 0 ); // no dtor called yet QCOMPARE( ptrDerived.data(), obj ); } QCOMPARE( dtor_called, 1 ); }
QActionList IpodPlaylistProvider::trackActions( Playlists::PlaylistPtr playlist, int trackIndex ) { QList<QAction *> actions; if( !m_playlists.contains( playlist ) ) // make following static cast safe return actions; KSharedPtr<IpodPlaylist> ipodPlaylist = KSharedPtr<IpodPlaylist>::staticCast( playlist ); switch( ipodPlaylist->type() ) { case IpodPlaylist::Normal: actions << Playlists::UserPlaylistProvider::trackActions( playlist, trackIndex ); break; case IpodPlaylist::Stale: case IpodPlaylist::Orphaned: actions << m_coll->m_consolidateAction; break; } return actions; }
void marshall_PackageStructurePtr(Marshall *m) { switch(m->action()) { case Marshall::FromVALUE: { break; } case Marshall::ToVALUE: { KSharedPtr<Plasma::PackageStructure> *ptr = new KSharedPtr<Plasma::PackageStructure>(*(KSharedPtr<Plasma::PackageStructure>*)m->item().s_voidp); if (ptr == 0) { *(m->var()) = Qnil; break; } Plasma::PackageStructure * package = ptr->data(); VALUE obj = getPointerObject(package); if (obj == Qnil) { smokeruby_object * o = ALLOC(smokeruby_object); o->smoke = m->smoke(); o->classId = m->smoke()->idClass("Plasma::PackageStructure").index; o->ptr = package; o->allocated = false; obj = set_obj_info("Plasma::PackageStructure", o); } *(m->var()) = obj; if (m->cleanup()) { } break; } default: m->unsupported(); break; } }
void FileNameSearchProtocol::searchDirectory(const KUrl& directory) { // Don't try to iterate the pseudo filesystem directories of Linux if (directory.path() == QLatin1String("/dev") || directory.path() == QLatin1String("/proc") || directory.path() == QLatin1String("/sys")) { return; } // Get all items of the directory KDirLister *dirLister = new KDirLister(); dirLister->setDelayedMimeTypes(false); dirLister->setAutoErrorHandlingEnabled(false, 0); dirLister->openUrl(directory); QEventLoop eventLoop; QObject::connect(dirLister, SIGNAL(canceled()), &eventLoop, SLOT(quit())); QObject::connect(dirLister, SIGNAL(completed()), &eventLoop, SLOT(quit())); eventLoop.exec(); // Visualize all items that match the search pattern QList<KUrl> pendingDirs; const KFileItemList items = dirLister->items(); foreach (const KFileItem& item, items) { bool addItem = false; if (!m_regExp || item.name().contains(*m_regExp)) { addItem = true; if (!m_checkType.isEmpty()) { addItem = false; const QStringList types = m_checkType.split(";"); const KSharedPtr<KMimeType> mime = item.determineMimeType(); foreach (const QString& t, types) { if (mime->is(t)) { addItem = true; } } }
KexiMacroError::KexiMacroError(KexiMainWindow* mainwin, KSharedPtr<KoMacro::Context> context) : KexiMacroErrorBase(mainwin, "KexiMacroError" , /*WFlags*/ Qt::WDestructiveClose) , d(new Private(mainwin, context)) { //setText(i18n("Execution failed")); //caption //errortext, errorlist, continuebtn,cancelbtn, designerbtn KoMacro::Exception* exception = context->exception(); iconlbl->setPixmap(KGlobal::instance()->iconLoader()->loadIcon("messagebox_critical", KIcon::Small, 32)); errorlbl->setText(i18n("<qt>Failed to execute the macro \"%1\".<br>%2</qt>").arg( context->macro()->name() ).arg( exception->errorMessage() )); int i = 1; KoMacro::MacroItem::List items = context->macro()->items(); for (KoMacro::MacroItem::List::ConstIterator mit = items.begin(); mit != items.end(); mit++) { KListViewItem* listviewitem = new KListViewItem(errorlist); listviewitem->setText(0,QString("%1").arg(i++)); listviewitem->setText(1,i18n("Action")); KSharedPtr<KoMacro::MacroItem> macroitem = *mit; if (macroitem != 0 && macroitem->action() != 0) { listviewitem->setText(2,macroitem->action()->name()); } if(macroitem == context->macroItem()) { listviewitem->setOpen(true); listviewitem->setSelected(true); errorlist->setSelected(listviewitem, true); errorlist->ensureItemVisible(listviewitem); } KoMacro::Variable::Map variables = macroitem->variables(); KoMacro::Variable::Map::ConstIterator vit; for ( vit = variables.begin(); vit != variables.end(); ++vit ) { KListViewItem* child = new KListViewItem(listviewitem); child->setText(1,vit.key()); child->setText(2,vit.data()->toString()); } } connect(designerbtn, SIGNAL(clicked()), this, SLOT(designbtnClicked())); connect(continuebtn, SIGNAL(clicked()), this, SLOT(continuebtnClicked())); }
void KSharedPtrTest::testWithStrings() { SharedString s = QString::fromLatin1( "Hello" ); SharedString s2 = QString::fromLatin1( "Foo" ); SharedString s3 = QString::fromLatin1( "Bar" ); KSharedPtr<SharedString>u(new SharedString( s )); QCOMPARE( *u, s ); QVERIFY( u.isUnique() ); KSharedPtr<SharedString> v; QVERIFY( u.isUnique() ); QVERIFY( !v ); v = u; QVERIFY( !u.isUnique() ); QCOMPARE( *v, s ); QVERIFY( !v.isUnique() ); KSharedPtr<SharedString> w = v; QVERIFY( !u.isUnique() ); QCOMPARE( u.count(), 3 ); QVERIFY( !v.isUnique() ); QCOMPARE( v.count(), 3 ); QVERIFY( !w.isUnique() ); QCOMPARE( w.count(), 3 ); // v->clear(); v = 0; QVERIFY( u ); QVERIFY( !u.isUnique() ); QCOMPARE( u.count(), 2 ); QVERIFY( !v ); QVERIFY( !v.isUnique() ); QCOMPARE( *w, s ); QVERIFY( !w.isUnique() ); QCOMPARE( w.count(), 2 ); u = v = w; QCOMPARE( *u, s ); QVERIFY( !u.isUnique() ); QCOMPARE( *v, s ); QVERIFY( !v.isUnique() ); QCOMPARE( *w, s ); QVERIFY( !w.isUnique() ); u->mStr = s2.mStr; QCOMPARE( *u, s2 ); QVERIFY( !u.isUnique() ); QCOMPARE( *v, s2 ); QVERIFY( !v.isUnique() ); // QCOMPARE( *w, s2 ); // QVERIFY( !w.isUnique() ); }