本文整理汇总了C++中KFileItem::mimeTypePtr方法的典型用法代码示例。如果您正苦于以下问题:C++ KFileItem::mimeTypePtr方法的具体用法?C++ KFileItem::mimeTypePtr怎么用?C++ KFileItem::mimeTypePtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KFileItem
的用法示例。
在下文中一共展示了KFileItem::mimeTypePtr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execAutorun
bool MediaNotifier::execAutorun(const KFileItem &medium, const QString &path, const QString &autorunFile)
{
// The desktop environment MUST prompt the user for confirmation
// before automatically starting an application.
QString mediumType = medium.mimeTypePtr()->name();
QString text = i18n(
"An autorun file has been found on your '%1'."
" Do you want to execute it?\n"
"Note that executing a file on a medium may compromise"
" your system's security")
.arg(mediumType);
QString caption = i18n("Autorun - %1").arg(medium.url().prettyURL());
KGuiItem yes = KStdGuiItem::yes();
KGuiItem no = KStdGuiItem::no();
int options = KMessageBox::Notify | KMessageBox::Dangerous;
int answer = KMessageBox::warningYesNo(0L, text, caption, yes, no, QString::null, options);
if(answer == KMessageBox::Yes)
{
// When an Autostart file has been detected and the user has
// confirmed its execution the autostart file MUST be executed
// with the current working directory ( CWD ) set to the root
// directory of the medium.
KProcess proc;
proc << "sh" << autorunFile;
proc.setWorkingDirectory(path);
proc.start();
proc.detach();
}
return true;
}
示例2: updateURL
void DolphinView::updateURL()
{
KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
static_cast<KFileView*>(m_detailsView);
KFileItem* fileItem = fileView->currentFileItem();
if (fileItem == 0) {
return;
}
if (fileItem->isDir()) {
// Prefer the local path over the URL. This assures that the
// volume space information is correct. Assuming that the URL is media:/sda1,
// and the local path is /windows/C: For the URL the space info is related
// to the root partition (and hence wrong) and for the local path the space
// info is related to the windows partition (-> correct).
const QString localPath(fileItem->localPath());
if (localPath.isEmpty()) {
setURL(fileItem->url());
}
else {
setURL(KURL(localPath));
}
}
else if (fileItem->isFile()) {
// allow to browse through ZIP and tar files
KMimeType::Ptr mime = fileItem->mimeTypePtr();
if (mime->is("application/x-zip")) {
KURL url = fileItem->url();
url.setProtocol("zip");
setURL(url);
}
else if (mime->is("application/x-tar") ||
mime->is("application/x-tarz") ||
mime->is("application/x-tbz") ||
mime->is("application/x-tgz") ||
mime->is("application/x-tzo")) {
KURL url = fileItem->url();
url.setProtocol("tar");
setURL(url);
}
else {
fileItem->run();
}
}
else {
fileItem->run();
}
}
示例3: checkDesktopFile
/**
* Returns true if this is a desktop file.
* Mimetype determination is optional.
*/
static bool checkDesktopFile(const KFileItem& item, bool _determineMimeType)
{
// only local files
bool isLocal;
const KUrl url = item.mostLocalUrl(isLocal);
if (!isLocal)
return false;
// only regular files
if (!item.isRegularFile())
return false;
// only if readable
if (!item.isReadable())
return false;
// return true if desktop file
KMimeType::Ptr mime = _determineMimeType ? item.determineMimeType() : item.mimeTypePtr();
return mime->is("application/x-desktop");
}
示例4: execAutoopen
bool MediaNotifier::execAutoopen(const KFileItem &medium, const QString &path, const QString &autoopenFile)
{
// An Autoopen file MUST contain a single relative path that points
// to a non-executable file contained on the medium. [...]
QFile file(path + "/" + autoopenFile);
file.open(IO_ReadOnly);
QTextStream stream(&file);
QString relative_path = stream.readLine().stripWhiteSpace();
// The relative path MUST NOT contain path components that
// refer to a parent directory ( ../ )
if(relative_path.startsWith("/") || relative_path.contains("../"))
{
return false;
}
// The desktop environment MUST verify that the relative path points
// to a file that is actually located on the medium [...]
QString resolved_path = KStandardDirs::realFilePath(path + "/" + relative_path);
if(!resolved_path.startsWith(path))
{
return false;
}
QFile document(resolved_path);
// TODO: What about FAT all files are executable...
// If the relative path points to an executable file then the desktop
// environment MUST NOT execute the file.
if(!document.exists() /*|| QFileInfo(document).isExecutable()*/)
{
return false;
}
KURL url = medium.url();
url.addPath(relative_path);
// The desktop environment MUST prompt the user for confirmation
// before opening the file.
QString mediumType = medium.mimeTypePtr()->name();
QString filename = url.filename();
QString text = i18n(
"An autoopen file has been found on your '%1'."
" Do you want to open '%2'?\n"
"Note that opening a file on a medium may compromise"
" your system's security")
.arg(mediumType)
.arg(filename);
QString caption = i18n("Autoopen - %1").arg(medium.url().prettyURL());
KGuiItem yes = KStdGuiItem::yes();
KGuiItem no = KStdGuiItem::no();
int options = KMessageBox::Notify | KMessageBox::Dangerous;
int answer = KMessageBox::warningYesNo(0L, text, caption, yes, no, QString::null, options);
// TODO: Take case of the "UNLESS" part?
// When an Autoopen file has been detected and the user has confirmed
// that the file indicated in the Autoopen file should be opened then
// the file indicated in the Autoopen file MUST be opened in the
// application normally preferred by the user for files of its kind
// UNLESS the user instructed otherwise.
if(answer == KMessageBox::Yes)
{
(void)new KRun(url);
}
return true;
}