本文整理汇总了C++中kparts::ReadOnlyPart类的典型用法代码示例。如果您正苦于以下问题:C++ ReadOnlyPart类的具体用法?C++ ReadOnlyPart怎么用?C++ ReadOnlyPart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReadOnlyPart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setData
void BinaryWidget::setData( const QByteArray &data )
{
delete mMainWidget;
QString mimetype;
KMimeType::Ptr mime = KMimeType::findByContent( data );
if ( mime && !mime->isDefault() )
mimetype = mime->name();
if ( !mimetype.isEmpty() ) {
KParts::ReadOnlyPart *part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype, QString(), this, this );
if ( part ) {
KTemporaryFile file;
file.setAutoRemove(false);
file.open();
file.write( data );
file.flush();
part->openUrl( KUrl( file.fileName() ) );
mMainWidget = part->widget();
} else {
mMainWidget = new QLabel( i18n( "No part found for visualization of mimetype %1", mimetype ), this );
}
mData = data;
mSaveButton->setEnabled( true );
} else {
mMainWidget = new QLabel( i18n( "Got data of unknown mimetype" ), this );
}
mLayout->addWidget( mMainWidget, 0, 0, 3, 1);
mMainWidget->show();
}
示例2: slotExecuteShellCommand
void KShellCmdPlugin::slotExecuteShellCommand()
{
KParts::ReadOnlyPart *part = qobject_cast<KParts::ReadOnlyPart *>(parent());
if (!part) {
KMessageBox::sorry(0L, i18n("KShellCmdPlugin::slotExecuteShellCommand: Program error, please report a bug."));
return;
}
KUrl url = KIO::NetAccess::mostLocalUrl(part->url(), NULL);
if (!url.isLocalFile()) {
KMessageBox::sorry(part->widget(), i18n("Executing shell commands works only on local directories."));
return;
}
QString path;
KParts::FileInfoExtension *ext = KParts::FileInfoExtension::childObject(part);
if (ext && ext->hasSelection() && (ext->supportedQueryModes() & KParts::FileInfoExtension::SelectedItems)) {
KFileItemList list = ext->queryFor(KParts::FileInfoExtension::SelectedItems);
QStringList fileNames;
Q_FOREACH (const KFileItem &item, list) {
fileNames << item.name();
}
path = KShell::joinArgs(fileNames);
}
示例3: kDebug
KParts::ReadOnlyPart *KGraphEditor::slotNewGraph()
{
kDebug();
KPluginFactory *factory = KPluginLoader("kgraphviewerpart").factory();
if (!factory)
{
// if we couldn't find our Part, we exit since the Shell by
// itself can't do anything useful
KMessageBox::error(this, i18n("Could not find the KGraphViewer part."));
kapp->quit();
// we return here, cause kapp->quit() only means "exit the
// next time we enter the event loop...
return NULL;
}
KParts::ReadOnlyPart* part = factory->create<KParts::ReadOnlyPart>("kgraphviewerpart", this);
KGraphViewerInterface *view = qobject_cast<KGraphViewerInterface *>(part);
if (!view)
{
// This should not happen
kError() << "Failed to get KPart" << endl;
return NULL;
}
view->setReadWrite();
QWidget *w = part->widget();
m_widget->addTab(w, QIcon( DesktopIcon("kgraphviewer") ), "");
m_widget->setCurrentWidget(w);
// createGUI(view);
m_tabsPartsMap[w] = part;
m_tabsFilesMap[w] = "";
// connect(this,SIGNAL(hide(KParts::Part*)),view,SLOT(slotHide(KParts::Part*)));
slotSetActiveGraph(part);
return part;
}
示例4: openFile
void FileManager::openFile( const QString& fileName, const QString& name, const QString& title, const QString& partName, const QVariantList& partParams )
{
if( fileName.isEmpty() )
return;
QString fullName = name.isEmpty() ? KUrl( fileName ).fileName() : name;
QString fullTitle = title.isEmpty() ? fullName : title;
if( d->parts.contains( fullName ) )
{
emit newPart( fullName, fullTitle );
return;
}
KMimeType::Ptr mime = KMimeType::findByPath( fileName );
KParts::ReadOnlyPart* part = 0;
KService::List parts;
if( !partName.isEmpty() )
{
KService::Ptr service = KService::serviceByDesktopName( partName );
if( !service.isNull() )
parts.append( service );
}
if( parts.count() == 0 )
{
parts.append( KMimeTypeTrader::self()->query( mime->name(), "KParts/ReadWritePart" ) );
parts.append( KMimeTypeTrader::self()->query( mime->name(), "KParts/ReadOnlyPart" ) );
if( mime->name().contains( "audio" ) && parts.count() == 0 )
parts.append( KService::serviceByStorageId( "dragonplayer_part.desktop" ) );
}
if( parts.count() > 0 )
{
part = parts.first()->createInstance<KParts::ReadWritePart>( 0, partParams );
if( !part )
part = parts.first()->createInstance<KParts::ReadOnlyPart>( 0, partParams );
}
if( part )
{
// Add the part if it is found
KUrl url( fileName );
part->openUrl( url );
d->parts.insert( fullName, part );
d->partManager->addPart( part, true );
emit newPart( fullName, fullTitle );
return;
}
// There really is no part that can be used.
// Instead, just open it in an external application.
// KRun* runner = new KRun( KUrl( fileName ), qApp->activeWindow() );
}
示例5: urlFocusedDocument
bool subversionPart::urlFocusedDocument( KURL &url ) {
KParts::ReadOnlyPart *part = dynamic_cast<KParts::ReadOnlyPart*>( partController()->activePart() );
if ( part ) {
if (part->url().isLocalFile() ) {
url = part->url();
return true;
}
}
return false;
}
示例6: currentFile
QString PerforcePart::currentFile()
{
KParts::ReadOnlyPart *part = dynamic_cast<KParts::ReadOnlyPart*>( partController()->activePart() );
if ( part ) {
KURL url = part->url();
if ( url.isLocalFile() )
return url.path();
}
return QString::null;
}
示例7: slotSwitchToView
void RubySupportPart::slotSwitchToView()
{
KParts::Part *activePart = partController()->activePart();
if (!activePart)
return;
KParts::ReadOnlyPart *ropart = dynamic_cast<KParts::ReadOnlyPart*>(activePart);
if (!ropart)
return;
QFileInfo file(ropart->url().path());
if (!file.exists())
return;
QString ext = file.extension();
QString name = file.baseName();
QString switchTo = "";
if (ext == "rjs" || ext == "rxml" || ext == "rhtml" || ext == "js.rjs" || ext == "xml.builder" || ext == "html.erb")
{
//this is a view already, let's show the list of all views for this model
switchTo = file.dir().dirName();
}
else if (ext == "rb")
switchTo = name.remove(QRegExp("_controller$")).remove(QRegExp("_controller_test$")).remove(QRegExp("_test$"));
if (switchTo.isEmpty())
return;
if (switchTo.endsWith("s"))
switchTo = switchTo.mid(0, switchTo.length() - 1);
KURL::List urls;
QDir viewsDir;
QDir viewsDirS = QDir(project()->projectDirectory() + "/app/views/" + switchTo);
QDir viewsDirP = QDir(project()->projectDirectory() + "/app/views/" + switchTo + "s");
if (viewsDirS.exists())
viewsDir = viewsDirS;
else if (viewsDirP.exists())
viewsDir = viewsDirP;
else
return;
QStringList views = viewsDir.entryList();
for (QStringList::const_iterator it = views.begin(); it != views.end(); ++it)
{
QString viewName = *it;
if ( !(viewName.endsWith("~") || viewName == "." || viewName == "..") )
urls << KURL::fromPathOrURL(viewsDir.absPath() + "/" + viewName);
}
KDevQuickOpen *qo = extension<KDevQuickOpen>("KDevelop/QuickOpen");
if (qo)
qo->quickOpenFile(urls);
}
示例8: slotMimetype
void KWebDesktopRun::slotMimetype(KIO::Job *job, const QString &_type)
{
KIO::SimpleJob *sjob = static_cast< KIO::SimpleJob * >(job);
// Update our URL in case of a redirection
m_url = sjob->url();
QString type = _type; // necessary copy if we plan to use it
sjob->putOnHold();
kdDebug() << "slotMimetype : " << type << endl;
KParts::ReadOnlyPart *part = m_webDesktop->createPart(type);
// Now open the URL in the part
if(part)
part->openURL(m_url);
}
示例9: slotSwitchToTest
void RubySupportPart::slotSwitchToTest()
{
KParts::Part *activePart = partController()->activePart();
if (!activePart)
return;
KParts::ReadOnlyPart *ropart = dynamic_cast<KParts::ReadOnlyPart*>(activePart);
if (!ropart)
return;
QFileInfo file(ropart->url().path());
if (!file.exists())
return;
QString ext = file.extension();
QString name = file.baseName();
QString switchTo = "";
if (ext == "rjs" || ext == "rxml" || ext == "rhtml" || ext == "js.rjs" || ext == "xml.builder" || ext == "html.erb")
{
//this is a view already, let's show the list of all views for this model
switchTo = file.dir().dirName();
}
else if (ext == "rb")
switchTo = name.remove(QRegExp("_controller$")).remove(QRegExp("_controller_test$")).remove(QRegExp("_test$"));
if (switchTo.isEmpty())
return;
if (switchTo.endsWith("s"))
switchTo = switchTo.mid(0, switchTo.length() - 1);
KURL::List urls;
QString testDir = project()->projectDirectory() + "/test/";
QString functionalTestS = testDir + "functional/" + switchTo + "_controller_test.rb";
QString functionalTestP = testDir + "functional/" + switchTo + "s_controller_test.rb";
QString integrationTestS = testDir + "integration/" + switchTo + "_test.rb";
QString integrationTestP = testDir + "integration/" + switchTo + "s_test.rb";
QString unitTestS = testDir + "unit/" + switchTo + "_test.rb";
QString unitTestP = testDir + "unit/" + switchTo + "s_test.rb";
if (QFile::exists(functionalTestP)) urls << KURL::fromPathOrURL(functionalTestP);
if (QFile::exists(integrationTestP)) urls << KURL::fromPathOrURL(integrationTestP);
if (QFile::exists(unitTestP)) urls << KURL::fromPathOrURL(unitTestP);
if (QFile::exists(functionalTestS)) urls << KURL::fromPathOrURL(functionalTestS);
if (QFile::exists(integrationTestS)) urls << KURL::fromPathOrURL(integrationTestS);
if (QFile::exists(unitTestS)) urls << KURL::fromPathOrURL(unitTestS);
KDevQuickOpen *qo = extension<KDevQuickOpen>("KDevelop/QuickOpen");
if (qo && !urls.isEmpty())
qo->quickOpenFile(urls);
}
示例10: slotRefresh
void AutoRefresh::slotRefresh()
{
KParts::ReadOnlyPart *part = qobject_cast< KParts::ReadOnlyPart * >( parent() );
if ( !part ) {
QString title = i18nc( "@title:window", "Cannot Refresh Source" );
QString text = i18n( "<qt>This plugin cannot auto-refresh the current part.</qt>" );
KMessageBox::error( 0, text, title );
}
else
{
// Get URL
KUrl url = part->url();
part->openUrl( url );
}
}
示例11: slotOpenFile
void Shell::slotOpenFile()
{
//FIXME this is getting far to deeply indented... maybe some of it should be pulled out?
//check if there is an open tab...
if (mainView->currentIndex() == -1) {
//no tabs open so we can just use the openFileNewTab slot :D
slotOpenFileNewTab();
} else {
//check to see if the collection manager is open, and if thats our current tab
//since we can't open files with the collection manager...
if (mainView->indexOf(m_collection->widget()) == mainView->currentIndex()) {
//we're trying to open things in the collection... which is bad, so use a new tab :D
slotOpenFileNewTab();
} else {
//we have an open reader tab so...
//first get the filename from the user
QString filename = KFileDialog::getOpenFileName();
//check if the filename is null, open the file if its NOT null
if (!filename.isNull()) {
KUrl tempUrl = filename;
//might be a better way to get the part, but it works elsewhere so...
ReaderPage *curPage = qobject_cast<ReaderPage *>(mainView->widget(mainView->currentIndex()));
//this is kind of naive as most kparts support multiple mimetypes
//but i couldn't find an easy way to get a list of supported types
//from a kpart... FIXME
QString newMimeType = KMimeType::findByUrl(tempUrl)->name();
KParts::ReadOnlyPart *curpart = curPage->getPart();
if (curPage->getMimeType() == newMimeType) {
curpart->openUrl(tempUrl);
} else {
//if the mimetype has changed we need to delete the currentpage and open a replacement
ReaderPage *newPage = new ReaderPage(&tempUrl, this);
if (newPage) {
int index = mainView->currentIndex();
mainView->removeTab(index);
mainView->insertTab(index, newPage, tempUrl.fileName());
m_manager->replacePart(curpart, newPage->getPart());
// remove the old reader page from the open list and add the new page
openPagesList.replace(openPagesList.indexOf(curPage), newPage);
delete(curPage);
}
}
}
}
}
}
示例12: slotRefresh
void AutoRefresh::slotRefresh()
{
if ( !parent()->inherits("KParts::ReadOnlyPart") ) {
QString title = i18n( "Cannot Refresh Source" );
QString text = i18n( "<qt>This plugin cannot auto-refresh the current part.</qt>" );
QMessageBox::warning( 0, title, text );
}
else
{
KParts::ReadOnlyPart *part = (KParts::ReadOnlyPart *) parent();
// Get URL
KURL url = part->url();
part->openURL( url );
}
}
示例13: openUrl
void KGraphEditor::openUrl(const KUrl& url)
{
kDebug() << url;
KParts::ReadOnlyPart *part = slotNewGraph();
// (KGraphEditorSettings::parsingMode() == "external")
// ?kgv->setLayoutMethod(KGraphViewerInterface::ExternalProgram)
// :kgv->setLayoutMethod(KGraphViewerInterface::InternalLibrary);
QString label = url.path().section('/',-1,-1);
// @TODO set label
m_widget->setTabText(m_widget->currentIndex(), label);
m_tabsFilesMap[m_widget->currentWidget()] = url.path();
part->openUrl(url);
m_openedFiles.push_back(url.path());
}
示例14: QString
KParts::ReadOnlyPart *KonqViewFactory::create( QWidget *parentWidget, QObject * parent )
{
if ( !m_factory )
return 0;
KParts::ReadOnlyPart* part = m_factory->create<KParts::ReadOnlyPart>( parentWidget, parent, QString(), m_args );
if ( !part ) {
kError() << "No KParts::ReadOnlyPart created from" << m_libName;
} else {
QFrame* frame = qobject_cast<QFrame*>( part->widget() );
if ( frame ) {
frame->setFrameStyle( QFrame::NoFrame );
}
}
return part;
}
示例15: slotReadOut
void KHTMLPluginKTTSD::slotReadOut()
{
// The parent is a KParts::ReadOnlyPart (checked in constructor)
KParts::ReadOnlyPart* part = static_cast<KParts::ReadOnlyPart *>(parent());
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd"))
{
QString error;
if (KToolInvocation::startServiceByDesktopName("kttsd", QStringList(), &error)) {
KMessageBox::error(part->widget(), error, i18nc("@title:window", "Starting Jovie Text-to-Speech Service Failed") );
return;
}
}
// Find out if KTTSD supports xhtml (rich speak).
bool supportsXhtml = false;
org::kde::KSpeech kttsd( "org.kde.kttsd", "/KSpeech", QDBusConnection::sessionBus() );
QString talker = kttsd.defaultTalker();
QDBusReply<int> reply = kttsd.getTalkerCapabilities2(talker);
if ( !reply.isValid())
kDebug() << "D-Bus call getTalkerCapabilities2() failed, assuming non-XHTML support.";
else
{
supportsXhtml = reply.value() & KSpeech::tcCanParseHtml;
if (supportsXhtml)
kDebug() << "KTTS claims to support rich speak (XHTML to SSML).";
}
KParts::TextExtension* textExt = KParts::TextExtension::childObject(parent());
QString query;
const KParts::TextExtension::Format format = supportsXhtml ? KParts::TextExtension::HTML : KParts::TextExtension::PlainText;
if (textExt->hasSelection()) {
query = textExt->selectedText(format);
} else {
query = textExt->completeText(format);
}
// kDebug() << "query =" << query;
reply = kttsd.say(query, KSpeech::soNone);
if ( !reply.isValid()) {
KMessageBox::sorry(part->widget(), i18n("The D-Bus call say() failed."),
i18nc("@title:window", "D-Bus Call Failed"));
}
}