kio: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-19 02:54:36 +03:00
parent 7b38e92e43
commit af7077a0a3
3 changed files with 758 additions and 761 deletions

View file

@ -132,8 +132,9 @@ using namespace KDEPrivate;
static QString nameFromFileName(QString nameStr)
{
if ( nameStr.endsWith(QLatin1String(".desktop")) )
if (nameStr.endsWith(QLatin1String(".desktop"))) {
nameStr.truncate(nameStr.length() - 8);
}
// Make it human-readable (%2F => '/', ...)
return KIO::decodeFileName(nameStr);
}
@ -188,9 +189,9 @@ public:
QList<KPropertiesDialogPlugin*> m_pageList;
};
KPropertiesDialog::KPropertiesDialog (const KFileItem& item,
QWidget* parent)
: KPageDialog(parent), d(new KPropertiesDialogPrivate(this))
KPropertiesDialog::KPropertiesDialog(const KFileItem &item, QWidget *parent)
: KPageDialog(parent),
d(new KPropertiesDialogPrivate(this))
{
setCaption(i18n("Properties for %1", KIO::decodeFileName(item.url().fileName())));
@ -203,58 +204,59 @@ KPropertiesDialog::KPropertiesDialog (const KFileItem& item,
d->init();
}
KPropertiesDialog::KPropertiesDialog (const QString& title,
QWidget* parent)
: KPageDialog(parent), d(new KPropertiesDialogPrivate(this))
KPropertiesDialog::KPropertiesDialog(const QString &title, QWidget *parent)
: KPageDialog(parent),
d(new KPropertiesDialogPrivate(this))
{
setCaption(i18n("Properties for %1", title));
d->init();
}
KPropertiesDialog::KPropertiesDialog(const KFileItemList& _items,
QWidget* parent)
: KPageDialog(parent), d(new KPropertiesDialogPrivate(this))
KPropertiesDialog::KPropertiesDialog(const KFileItemList &items, QWidget *parent)
: KPageDialog(parent),
d(new KPropertiesDialogPrivate(this))
{
if ( _items.count() > 1 )
setCaption( i18np( "Properties for 1 item", "Properties for %1 Selected Items", _items.count() ) );
else
setCaption( i18n( "Properties for %1" , KIO::decodeFileName(_items.first().url().fileName())) );
if (items.count() > 1) {
setCaption(i18np("Properties for 1 item", "Properties for %1 Selected Items", items.count()));
} else {
setCaption(i18n("Properties for %1", KIO::decodeFileName(items.first().url().fileName())));
}
Q_ASSERT( !_items.isEmpty() );
d->m_singleUrl = _items.first().url();
Q_ASSERT(!items.isEmpty());
d->m_singleUrl = items.first().url();
Q_ASSERT(!d->m_singleUrl.isEmpty());
d->m_items = _items;
d->m_items = items;
d->init();
}
KPropertiesDialog::KPropertiesDialog (const KUrl& _url,
QWidget* parent)
: KPageDialog(parent), d(new KPropertiesDialogPrivate(this))
KPropertiesDialog::KPropertiesDialog(const KUrl &url, QWidget* parent)
: KPageDialog(parent),
d(new KPropertiesDialogPrivate(this))
{
setCaption( i18n( "Properties for %1" , KIO::decodeFileName(_url.fileName())) );
setCaption(i18n("Properties for %1", KIO::decodeFileName(url.fileName())));
d->m_singleUrl = _url;
d->m_singleUrl = url;
KIO::UDSEntry entry;
KIO::NetAccess::stat(_url, entry, parent);
KIO::NetAccess::stat(url, entry, parent);
d->m_items.append(KFileItem(entry, _url));
d->m_items.append(KFileItem(entry, url));
d->init();
}
KPropertiesDialog::KPropertiesDialog (const KUrl& _tempUrl, const KUrl& _currentDir,
const QString& _defaultName,
QWidget* parent)
: KPageDialog(parent), d(new KPropertiesDialogPrivate(this))
KPropertiesDialog::KPropertiesDialog(const KUrl &tempUrl, const KUrl &currentDir,
const QString &defaultName, QWidget *parent)
: KPageDialog(parent),
d(new KPropertiesDialogPrivate(this))
{
setCaption( i18n( "Properties for %1" , KIO::decodeFileName(_tempUrl.fileName())) );
setCaption(i18n("Properties for %1" , KIO::decodeFileName(tempUrl.fileName())));
d->m_singleUrl = _tempUrl;
d->m_defaultName = _defaultName;
d->m_currentDir = _currentDir;
d->m_singleUrl = tempUrl;
d->m_defaultName = defaultName;
d->m_currentDir = currentDir;
Q_ASSERT(!d->m_singleUrl.isEmpty());
// Create the KFileItem for the _template_ file, in order to read from it.
@ -262,8 +264,7 @@ KPropertiesDialog::KPropertiesDialog (const KUrl& _tempUrl, const KUrl& _current
d->init();
}
bool KPropertiesDialog::showDialog(const KFileItem& item, QWidget* parent,
bool modal)
bool KPropertiesDialog::showDialog(const KFileItem &item, QWidget *parent, bool modal)
{
// TODO: do we really want to show the win32 property dialog?
// This means we lose metainfo, support for .desktop files, etc. (DF)
@ -273,35 +274,31 @@ bool KPropertiesDialog::showDialog(const KFileItem& item, QWidget* parent,
} else {
dlg->show();
}
return true;
}
bool KPropertiesDialog::showDialog(const KUrl& _url, QWidget* parent,
bool modal)
bool KPropertiesDialog::showDialog(const KUrl &url, QWidget *parent, bool modal)
{
KPropertiesDialog* dlg = new KPropertiesDialog(_url, parent);
KPropertiesDialog* dlg = new KPropertiesDialog(url, parent);
if (modal) {
dlg->exec();
} else {
dlg->show();
}
return true;
}
bool KPropertiesDialog::showDialog(const KFileItemList& _items, QWidget* parent,
bool modal)
bool KPropertiesDialog::showDialog(const KFileItemList &items, QWidget *parent, bool modal)
{
if (_items.count()==1) {
const KFileItem item = _items.first();
if (item.entry().count() == 0 && item.localPath().isEmpty()) // this remote item wasn't listed by a slave
// Let's stat to get more info on the file
if (items.count() == 1) {
const KFileItem item = items.first();
if (item.entry().count() == 0 && item.localPath().isEmpty()) {
// this remote item wasn't listed by a slave, let's stat to get more info on the file
return KPropertiesDialog::showDialog(item.url(), parent, modal);
else
return KPropertiesDialog::showDialog(_items.first(), parent, modal);
}
KPropertiesDialog* dlg = new KPropertiesDialog(_items, parent);
return KPropertiesDialog::showDialog(items.first(), parent, modal);
}
KPropertiesDialog* dlg = new KPropertiesDialog(items, parent);
if (modal) {
dlg->exec();
} else {
@ -333,11 +330,11 @@ void KPropertiesDialog::showFileSharingPage()
}
}
void KPropertiesDialog::setFileSharingPage(QWidget* page) {
void KPropertiesDialog::setFileSharingPage(QWidget* page)
{
d->fileSharePage = page;
}
void KPropertiesDialog::setFileNameReadOnly(bool ro)
{
foreach(KPropertiesDialogPlugin *it, d->m_pageList) {
@ -360,8 +357,7 @@ KPropertiesDialog::~KPropertiesDialog()
void KPropertiesDialog::insertPlugin(KPropertiesDialogPlugin* plugin)
{
connect (plugin, SIGNAL (changed()),
plugin, SLOT (setDirty()));
connect(plugin, SIGNAL (changed()), plugin, SLOT (setDirty()));
d->m_pageList.append(plugin);
}
@ -391,16 +387,16 @@ QString KPropertiesDialog::defaultName() const
return d->m_defaultName;
}
bool KPropertiesDialog::canDisplay( const KFileItemList& _items )
bool KPropertiesDialog::canDisplay(const KFileItemList &items)
{
// TODO: cache the result of those calls. Currently we parse .desktop files far too many times
return KFilePropsPlugin::supports( _items ) ||
KFilePermissionsPropsPlugin::supports( _items ) ||
KDesktopPropsPlugin::supports( _items ) ||
KUrlPropsPlugin::supports( _items ) ||
KDevicePropsPlugin::supports( _items ) ||
KPreviewPropsPlugin::supports( _items ) ||
KFileMetaPropsPlugin::supports( _items );
return KFilePropsPlugin::supports(items) ||
KFilePermissionsPropsPlugin::supports(items) ||
KDesktopPropsPlugin::supports(items) ||
KUrlPropsPlugin::supports(items) ||
KDevicePropsPlugin::supports(items) ||
KPreviewPropsPlugin::supports(items) ||
KFileMetaPropsPlugin::supports(items);
}
void KPropertiesDialog::slotOk()
@ -414,8 +410,7 @@ void KPropertiesDialog::slotOk()
// dirty too. This is what makes it possible to save changes to a global
// desktop file into a local one. In other cases, it doesn't hurt.
for (pageListIt = d->m_pageList.constBegin(); pageListIt != d->m_pageList.constEnd(); ++pageListIt) {
if ( (*pageListIt)->isDirty() && filePropsPlugin )
{
if ((*pageListIt)->isDirty() && filePropsPlugin) {
filePropsPlugin->setDirty();
break;
}
@ -426,22 +421,20 @@ void KPropertiesDialog::slotOk()
// KPropertiesDialog::rename, so other tab will be ok with whatever order
// BUT for file copied from templates, we need to do the renaming first !
for (pageListIt = d->m_pageList.constBegin(); pageListIt != d->m_pageList.constEnd() && !d->m_aborted; ++pageListIt) {
if ( (*pageListIt)->isDirty() )
{
if ((*pageListIt)->isDirty()) {
kDebug(250) << "applying changes for" << (*pageListIt)->metaObject()->className();
(*pageListIt)->applyChanges();
// applyChanges may change d->m_aborted.
}
else {
} else {
kDebug(250) << "skipping page " << (*pageListIt)->metaObject()->className();
}
}
if ( !d->m_aborted && filePropsPlugin )
if (!d->m_aborted && filePropsPlugin) {
filePropsPlugin->postApplyChanges();
}
if ( !d->m_aborted )
{
if (!d->m_aborted) {
emit applied();
emit propertiesClosed();
deleteLater(); // somewhat like Qt::WA_DeleteOnClose would do.
@ -455,13 +448,14 @@ void KPropertiesDialog::slotCancel()
emit propertiesClosed();
deleteLater();
done( Rejected );
done(QDialog::Rejected);
}
void KPropertiesDialog::KPropertiesDialogPrivate::insertPages()
{
if (m_items.isEmpty())
if (m_items.isEmpty()) {
return;
}
if (KFilePropsPlugin::supports(m_items)) {
KPropertiesDialogPlugin *p = new KFilePropsPlugin(q);
@ -500,14 +494,16 @@ void KPropertiesDialog::KPropertiesDialogPrivate::insertPages()
//plugins
if ( m_items.count() != 1 )
if (m_items.count() != 1) {
return;
}
const KFileItem item = m_items.first();
const QString mimetype = item.mimetype();
if ( mimetype.isEmpty() )
if (mimetype.isEmpty()) {
return;
}
QString query = QString::fromLatin1(
"((not exist [X-KDE-Protocol]) or "
@ -518,8 +514,9 @@ void KPropertiesDialog::KPropertiesDialogPrivate::insertPages()
const KService::List offers = KMimeTypeTrader::self()->query(mimetype, "KPropertiesDialog/Plugin", query);
foreach (const KService::Ptr &ptr, offers) {
KPropertiesDialogPlugin *plugin = ptr->createInstance<KPropertiesDialogPlugin>(q);
if (!plugin)
if (!plugin) {
continue;
}
plugin->setObjectName(ptr->name());
q->insertPlugin(plugin);
@ -550,15 +547,15 @@ void KPropertiesDialog::updateUrl( const KUrl& _newUrl )
}
}
void KPropertiesDialog::rename( const QString& _name )
void KPropertiesDialog::rename(const QString &name)
{
Q_ASSERT(d->m_items.count() == 1);
kDebug(250) << "KPropertiesDialog::rename " << _name;
kDebug(250) << "KPropertiesDialog::rename " << name;
KUrl newUrl;
// if we're creating from a template : use currentdir
if (!d->m_currentDir.isEmpty()) {
newUrl = d->m_currentDir;
newUrl.addPath(_name);
newUrl.addPath(name);
} else {
QString tmpurl = d->m_singleUrl.url();
if (!tmpurl.isEmpty() && tmpurl.at(tmpurl.length() - 1) == '/') {
@ -567,7 +564,7 @@ void KPropertiesDialog::rename( const QString& _name )
}
newUrl = tmpurl;
newUrl.setFileName(_name);
newUrl.setFileName(name);
}
updateUrl(newUrl);
}
@ -589,11 +586,11 @@ public:
int fontHeight;
};
KPropertiesDialogPlugin::KPropertiesDialogPlugin( KPropertiesDialog *_props )
: QObject( _props ),
KPropertiesDialogPlugin::KPropertiesDialogPlugin(KPropertiesDialog *props)
: QObject(props),
d(new KPropertiesDialogPluginPrivate())
{
properties = _props;
properties = props;
d->fontHeight = 2*properties->fontMetrics().height();
}
@ -602,7 +599,6 @@ KPropertiesDialogPlugin::~KPropertiesDialogPlugin()
delete d;
}
void KPropertiesDialogPlugin::setDirty(bool b)
{
d->m_bDirty = b;
@ -634,18 +630,20 @@ class KFilePropsPlugin::KFilePropsPluginPrivate
{
public:
KFilePropsPluginPrivate()
: dirSizeJob(nullptr),
dirSizeUpdateTimer(nullptr),
m_frame(nullptr),
m_capacityBar(nullptr),
m_lined(nullptr),
m_linkTargetLineEdit(nullptr)
{
dirSizeJob = 0L;
dirSizeUpdateTimer = 0L;
m_lined = 0;
m_capacityBar = 0;
m_linkTargetLineEdit = 0;
}
~KFilePropsPluginPrivate()
{
if ( dirSizeJob )
if (dirSizeJob) {
dirSizeJob->kill();
}
}
KIO::DirectorySizeJob * dirSizeJob;
QTimer *dirSizeUpdateTimer;
@ -676,8 +674,9 @@ public:
QString oldName;
};
KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
: KPropertiesDialogPlugin( _props ),d(new KFilePropsPluginPrivate)
KFilePropsPlugin::KFilePropsPlugin(KPropertiesDialog *props)
: KPropertiesDialogPlugin(props),
d(new KFilePropsPluginPrivate())
{
d->bMultiple = (properties->items().count() > 1);
d->bIconChanged = false;
@ -697,17 +696,20 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
QString iconStr = KMimeType::iconNameForUrl(url, mode);
QString directory = properties->kurl().directory();
QString protocol = properties->kurl().protocol();
d->bKDesktopMode = protocol == QLatin1String("desktop") ||
properties->currentDir().protocol() == QLatin1String("desktop");
d->bKDesktopMode = (
protocol == QLatin1String("desktop") ||
properties->currentDir().protocol() == QLatin1String("desktop")
);
QString mimeComment = item.mimeComment();
d->mimeType = item.mimetype();
KIO::filesize_t totalSize = item.size();
QString magicMimeComment;
if (isLocal) {
KMimeType::Ptr magicMimeType = KMimeType::findByFileContent(url.toLocalFile());
if ( magicMimeType->name() != KMimeType::defaultMimeType() )
if (magicMimeType->name() != KMimeType::defaultMimeType()) {
magicMimeComment = magicMimeType->comment();
}
}
// Those things only apply to 'single file' mode
QString filename;
@ -715,8 +717,8 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
d->m_bFromTemplate = false;
// And those only to 'multiple' mode
uint iDirCount = hasDirs ? 1 : 0;
uint iFileCount = 1-iDirCount;
uint iDirCount = (hasDirs ? 1 : 0);
uint iFileCount = (iDirCount - 1);
d->m_frame = new QFrame();
properties->addPage(d->m_frame, i18nc("@title:tab File properties", "&General"));
@ -732,16 +734,16 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
vbl->addLayout(grid);
int curRow = 0;
if ( !d->bMultiple )
{
if (!d->bMultiple) {
QString path;
if (!d->m_bFromTemplate) {
isTrash = (properties->kurl().protocol().toLower() == "trash");
// Extract the full name, but without file: for local files
if ( isReallyLocal )
if (isReallyLocal) {
path = properties->kurl().toLocalFile();
else
} else {
path = properties->kurl().prettyUrl();
}
} else {
path = properties->currentDir().path(KUrl::AddTrailingSlash) + properties->defaultName();
directory = properties->currentDir().prettyUrl();
@ -773,56 +775,58 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
}
d->oldName = filename;
}
else
{
} else {
// Multiple items: see what they have in common
const KFileItemList items = properties->items();
KFileItemList::const_iterator kit = items.begin();
const KFileItemList::const_iterator kend = items.end();
for ( ++kit /*no need to check the first one again*/ ; kit != kend; ++kit )
{
for ( ++kit /*no need to check the first one again*/ ; kit != kend; ++kit) {
const KUrl url = (*kit).url();
kDebug(250) << "KFilePropsPlugin::KFilePropsPlugin " << url.prettyUrl();
// The list of things we check here should match the variables defined
// at the beginning of this method.
if ( url.isLocalFile() != isLocal )
if (url.isLocalFile() != isLocal) {
isLocal = false; // not all local
if ( bDesktopFile && (*kit).isDesktopFile() != bDesktopFile )
}
if (bDesktopFile && (*kit).isDesktopFile() != bDesktopFile) {
bDesktopFile = false; // not all desktop files
if ( (*kit).mode() != mode )
}
if ((*kit).mode() != mode) {
mode = (mode_t)0;
if ( KMimeType::iconNameForUrl(url, mode) != iconStr )
}
if (KMimeType::iconNameForUrl(url, mode) != iconStr) {
iconStr = "document-multiple";
if ( url.directory() != directory )
}
if (url.directory() != directory) {
directory.clear();
if ( url.protocol() != protocol )
}
if (url.protocol() != protocol) {
protocol.clear();
if ( !mimeComment.isNull() && (*kit).mimeComment() != mimeComment )
}
if (!mimeComment.isNull() && (*kit).mimeComment() != mimeComment) {
mimeComment.clear();
}
if (isLocal && !magicMimeComment.isNull()) {
KMimeType::Ptr magicMimeType = KMimeType::findByFileContent(url.toLocalFile());
if ( magicMimeType->comment() != magicMimeComment )
if (magicMimeType->comment() != magicMimeComment) {
magicMimeComment.clear();
}
}
if ( isLocal && url.path() == QLatin1String("/") )
if (isLocal && url.path() == QLatin1String("/")) {
hasRoot = true;
if ( (*kit).isDir() && !(*kit).isLink() )
{
}
if ((*kit).isDir() && !(*kit).isLink()) {
iDirCount++;
hasDirs = true;
}
else
{
} else {
iFileCount++;
totalSize += (*kit).size();
}
}
}
if (!isReallyLocal && !protocol.isEmpty())
{
if (!isReallyLocal && !protocol.isEmpty()) {
directory += ' ';
directory += '(';
directory += protocol;
@ -843,17 +847,20 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
KDesktopFile config(url.toLocalFile());
KConfigGroup group = config.desktopGroup();
iconStr = group.readEntry("Icon");
if ( config.hasDeviceType() )
if (config.hasDeviceType()) {
iconButton->setIconType( KIconLoader::Desktop, KIconLoader::Device);
else
} else {
iconButton->setIconType( KIconLoader::Desktop, KIconLoader::Application);
}
} else {
iconButton->setIconType(KIconLoader::Desktop, KIconLoader::Place);
}
iconButton->setIcon(iconStr);
d->iconArea = iconButton;
connect(iconButton, SIGNAL(iconChanged(QString)),
this, SLOT(slotIconChanged()));
connect(
iconButton, SIGNAL(iconChanged(QString)),
this, SLOT(slotIconChanged())
);
} else {
QLabel *iconLabel = new QLabel(d->m_frame);
int bsize = 66 + 2 * iconLabel->style()->pixelMetric(QStyle::PM_ButtonMargin);
@ -863,16 +870,15 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
}
grid->addWidget(d->iconArea, curRow, 0, Qt::AlignLeft);
if (d->bMultiple || isTrash || hasRoot)
{
if (d->bMultiple || isTrash || hasRoot) {
QLabel *lab = new QLabel(d->m_frame);
if ( d->bMultiple )
if (d->bMultiple) {
lab->setText(KIO::itemsSummaryString(iFileCount + iDirCount, iFileCount, iDirCount, 0, false));
else
} else {
lab->setText(filename);
}
d->nameArea = lab;
} else
{
} else {
d->m_lined = new KLineEdit(d->m_frame);
d->m_lined->setText(filename);
d->nameArea = d->m_lined;
@ -884,17 +890,19 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
// Enhanced rename: Don't highlight the file extension.
QString extension = KMimeType::extractKnownExtension(filename);
if ( !extension.isEmpty() )
if (!extension.isEmpty()) {
d->m_lined->setSelection(0, filename.length() - extension.length() - 1);
else
{
} else {
int lastDot = filename.lastIndexOf('.');
if (lastDot > 0)
if (lastDot > 0) {
d->m_lined->setSelection(0, lastDot);
}
}
connect( d->m_lined, SIGNAL(textChanged(QString)),
this, SLOT(nameFileChanged(QString)) );
connect(
d->m_lined, SIGNAL(textChanged(QString)),
this, SLOT(nameFileChanged(QString))
);
}
grid->addWidget(d->nameArea, curRow++, 2);
@ -903,7 +911,7 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
grid->addWidget(sep, curRow, 0, 1, 3);
++curRow;
QLabel *l;
QLabel *l = nullptr;
if (!mimeComment.isEmpty() && !isTrash) {
l = new QLabel(i18n("Type:"), d->m_frame );
grid->addWidget(l, curRow, 0, Qt::AlignRight | Qt::AlignTop);
@ -917,16 +925,16 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // Minimum still makes the button grow to the entire layout width
button->setIcon( KIcon(QString::fromLatin1("configure")) );
if ( d->mimeType == KMimeType::defaultMimeType() )
if (d->mimeType == KMimeType::defaultMimeType()) {
button->setText(i18n("Create New File Type"));
else
} else {
button->setText(i18n("File Type Options"));
}
connect(button, SIGNAL(clicked()), SLOT(slotEditFileType()));
}
if ( !magicMimeComment.isEmpty() && magicMimeComment != mimeComment )
{
if (!magicMimeComment.isEmpty() && magicMimeComment != mimeComment) {
l = new QLabel(i18n("Contents:"), d->m_frame);
grid->addWidget(l, curRow, 0, Qt::AlignRight);
@ -934,8 +942,7 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
grid->addWidget(l, curRow++, 2);
}
if ( !directory.isEmpty() )
{
if (!directory.isEmpty()) {
l = new QLabel(i18n("Location:"), d->m_frame);
grid->addWidget(l, curRow, 0, Qt::AlignRight);
@ -944,8 +951,9 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
l->setLayoutDirection(Qt::LeftToRight);
// but if we are in RTL mode, align the text to the right
// otherwise the text is on the wrong side of the dialog
if (properties->layoutDirection() == Qt::RightToLeft)
if (properties->layoutDirection() == Qt::RightToLeft) {
l->setAlignment(Qt::AlignRight);
}
l->setTextInteractionFlags(Qt::TextSelectableByMouse|Qt::TextSelectableByKeyboard);
grid->addWidget(l, curRow++, 2);
}
@ -956,15 +964,14 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
d->m_sizeLabel = new QLabel(d->m_frame);
grid->addWidget(d->m_sizeLabel, curRow++, 2);
if ( !hasDirs ) // Only files [and symlinks]
{
if (!hasDirs) {
// Only files [and symlinks]
d->m_sizeLabel->setText(QString::fromLatin1("%1 (%2)").arg(KIO::convertSize(totalSize))
.arg(KGlobal::locale()->formatNumber(totalSize, 0)));
d->m_sizeDetermineButton = 0L;
d->m_sizeStopButton = 0L;
}
else // Directory
{
} else {
// Directory
QHBoxLayout* sizelay = new QHBoxLayout();
grid->addLayout(sizelay, curRow++, 2);
@ -978,14 +985,13 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
sizelay->addStretch(10); // so that the buttons don't grow horizontally
// auto-launch for local dirs only, and not for '/'
if ( isLocal && !hasRoot )
{
if (isLocal && !hasRoot) {
d->m_sizeDetermineButton->setText(i18n("Refresh"));
slotSizeDetermine();
}
else
} else {
d->m_sizeStopButton->setEnabled(false);
}
}
if (!d->bMultiple && item.isLink()) {
l = new QLabel(i18n("Points to:"), d->m_frame);
@ -996,11 +1002,10 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
connect(d->m_linkTargetLineEdit, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
}
if (!d->bMultiple) // Dates for multiple don't make much sense...
{
if (!d->bMultiple) {
// Dates for multiple don't make much sense...
KDateTime dt = item.time(KFileItem::CreationTime);
if ( !dt.isNull() )
{
if (!dt.isNull()) {
l = new QLabel(i18n("Created:"), d->m_frame);
grid->addWidget(l, curRow, 0, Qt::AlignRight);
@ -1009,8 +1014,7 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
}
dt = item.time(KFileItem::ModificationTime);
if ( !dt.isNull() )
{
if (!dt.isNull()) {
l = new QLabel(i18n("Modified:"), d->m_frame);
grid->addWidget(l, curRow, 0, Qt::AlignRight);
@ -1019,8 +1023,7 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
}
dt = item.time(KFileItem::AccessTime);
if ( !dt.isNull() )
{
if (!dt.isNull()) {
l = new QLabel(i18n("Accessed:"), d->m_frame);
grid->addWidget(l, curRow, 0, Qt::AlignRight);
@ -1029,19 +1032,17 @@ KFilePropsPlugin::KFilePropsPlugin( KPropertiesDialog *_props )
}
}
if ( isLocal && hasDirs ) // only for directories
{
if (isLocal && hasDirs) {
// only for directories
KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(url.toLocalFile());
if (mp) {
KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mp->mountPoint());
if(info.size() != 0 )
{
if (info.size() != 0) {
sep = new KSeparator(Qt::Horizontal, d->m_frame);
grid->addWidget(sep, curRow, 0, 1, 3);
++curRow;
if (mp->mountPoint() != "/")
{
if (mp->mountPoint() != "/") {
l = new QLabel(i18n("Mounted on:"), d->m_frame);
grid->addWidget(l, curRow, 0, Qt::AlignRight);
@ -1084,11 +1085,9 @@ bool KFilePropsPlugin::enableIconButton() const
void KFilePropsPlugin::setFileNameReadOnly(bool ro)
{
if ( d->m_lined && !d->m_bFromTemplate )
{
if (d->m_lined && !d->m_bFromTemplate) {
d->m_lined->setReadOnly(ro);
if (ro)
{
if (ro) {
// Don't put the initial focus on the line edit when it is ro
properties->setButtonFocus(KDialog::Ok);
}
@ -1100,10 +1099,11 @@ void KFilePropsPlugin::slotEditFileType()
QString mime;
if (d->mimeType == KMimeType::defaultMimeType()) {
const int pos = d->oldFileName.lastIndexOf('.');
if (pos != -1)
if (pos != -1) {
mime = '*' + d->oldFileName.mid(pos);
else
} else {
mime = '*';
}
} else {
mime = d->mimeType;
}
@ -1133,11 +1133,12 @@ void KFilePropsPlugin::determineRelativePath( const QString & path )
{
// now let's make it relative
d->m_sRelativePath =KGlobal::dirs()->relativeLocation("xdgdata-apps", path);
if (d->m_sRelativePath.startsWith('/'))
if (d->m_sRelativePath.startsWith('/')) {
d->m_sRelativePath.clear();
else
} else {
d->m_sRelativePath = path;
}
}
void KFilePropsPlugin::slotFoundMountPoint(const QString &,
quint64 kibSize,
@ -1148,7 +1149,8 @@ void KFilePropsPlugin::slotFoundMountPoint( const QString&,
i18nc("Available space out of total partition size (percent used)", "%1 free of %2 (%3% used)",
KIO::convertSizeFromKiB(kibAvail),
KIO::convertSizeFromKiB(kibSize),
100 - (int)(100.0 * kibAvail / kibSize) ));
100 - (int)(100.0 * kibAvail / kibSize))
);
d->m_capacityBar->setValue(100 - (int)(100.0 * kibAvail / kibSize));
}
@ -1163,15 +1165,15 @@ void KFilePropsPlugin::slotDirSizeUpdate()
KIO::convertSize(totalSize),
totalSize,
i18np("1 file", "%1 files", totalFiles),
i18np("1 sub-folder", "%1 sub-folders", totalSubdirs)));
i18np("1 sub-folder", "%1 sub-folders", totalSubdirs))
);
}
void KFilePropsPlugin::slotDirSizeFinished(KJob *job)
{
if (job->error())
if (job->error()) {
d->m_sizeLabel->setText( job->errorString());
else
{
} else {
KIO::filesize_t totalSize = d->dirSizeJob->totalSize();
KIO::filesize_t totalFiles = d->dirSizeJob->totalFiles();
KIO::filesize_t totalSubdirs = d->dirSizeJob->totalSubdirs();
@ -1198,17 +1200,20 @@ void KFilePropsPlugin::slotSizeDetermine()
d->dirSizeJob = KIO::directorySize(properties->items());
d->dirSizeUpdateTimer = new QTimer(this);
connect( d->dirSizeUpdateTimer, SIGNAL(timeout()),
SLOT(slotDirSizeUpdate()) );
connect(
d->dirSizeUpdateTimer, SIGNAL(timeout()),
this, SLOT(slotDirSizeUpdate())
);
d->dirSizeUpdateTimer->start(500);
connect( d->dirSizeJob, SIGNAL(result(KJob*)),
SLOT(slotDirSizeFinished(KJob*)) );
connect(
d->dirSizeJob, SIGNAL(result(KJob*)),
this, SLOT(slotDirSizeFinished(KJob*))
);
d->m_sizeStopButton->setEnabled(true);
d->m_sizeDetermineButton->setEnabled(false);
// also update the "Free disk space" display
if ( d->m_capacityBar )
{
if (d->m_capacityBar) {
bool isLocal;
const KFileItem item = properties->item();
KUrl url = item.mostLocalUrl(isLocal);
@ -1224,16 +1229,15 @@ void KFilePropsPlugin::slotSizeDetermine()
void KFilePropsPlugin::slotSizeStop()
{
if ( d->dirSizeJob )
{
if (d->dirSizeJob) {
KIO::filesize_t totalSize = d->dirSizeJob->totalSize();
d->m_sizeLabel->setText(i18n("At least %1",
KIO::convertSize(totalSize)));
d->m_sizeLabel->setText(i18n("At least %1", KIO::convertSize(totalSize)));
d->dirSizeJob->kill();
d->dirSizeJob = 0;
}
if ( d->dirSizeUpdateTimer )
if (d->dirSizeUpdateTimer) {
d->dirSizeUpdateTimer->stop();
}
d->m_sizeStopButton->setEnabled(false);
d->m_sizeDetermineButton->setEnabled(true);
@ -1244,26 +1248,26 @@ KFilePropsPlugin::~KFilePropsPlugin()
delete d;
}
bool KFilePropsPlugin::supports( const KFileItemList& /*_items*/ )
bool KFilePropsPlugin::supports(const KFileItemList &/*items*/)
{
return true;
}
void KFilePropsPlugin::applyChanges()
{
if ( d->dirSizeJob )
if (d->dirSizeJob) {
slotSizeStop();
}
kDebug(250) << "KFilePropsPlugin::applyChanges";
if (qobject_cast<QLineEdit*>(d->nameArea))
{
if (qobject_cast<QLineEdit*>(d->nameArea)) {
QString n = ((QLineEdit *) d->nameArea)->text();
// Remove trailing spaces (#4345)
while ( ! n.isEmpty() && n[n.length()-1].isSpace() )
while (!n.isEmpty() && n[n.length()-1].isSpace()) {
n.truncate(n.length() - 1);
if ( n.isEmpty() )
{
}
if (n.isEmpty()) {
KMessageBox::sorry(properties, i18n("The new file name is empty."));
properties->abortApplying();
return;
@ -1272,43 +1276,54 @@ void KFilePropsPlugin::applyChanges()
// Do we need to rename the file ?
kDebug(250) << "oldname = " << d->oldName;
kDebug(250) << "newname = " << n;
if ( d->oldName != n || d->m_bFromTemplate ) { // true for any from-template file
if (d->oldName != n || d->m_bFromTemplate) {
// true for any from-template file
KIO::Job * job = 0L;
KUrl oldurl = properties->kurl();
QString newFileName = KIO::encodeFileName(n);
if (d->bDesktopFile && !newFileName.endsWith(QLatin1String(".desktop")))
if (d->bDesktopFile && !newFileName.endsWith(QLatin1String(".desktop"))) {
newFileName += ".desktop";
}
// Tell properties. Warning, this changes the result of properties->kurl() !
properties->rename(newFileName);
// Update also relative path (for apps and mimetypes)
if ( !d->m_sRelativePath.isEmpty() )
if (!d->m_sRelativePath.isEmpty()) {
determineRelativePath(properties->kurl().toLocalFile());
}
kDebug(250) << "New URL = " << properties->kurl().url();
kDebug(250) << "old = " << oldurl.url();
// Don't remove the template !!
if ( !d->m_bFromTemplate ) // (normal renaming)
if (!d->m_bFromTemplate) {
// (normal renaming)
job = KIO::moveAs(oldurl, properties->kurl());
else // Copying a template
} else {
// Copying a template
job = KIO::copyAs(oldurl, properties->kurl());
}
connect( job, SIGNAL(result(KJob*)),
SLOT(slotCopyFinished(KJob*)) );
connect( job, SIGNAL(renamed(KIO::Job*,KUrl,KUrl)),
SLOT(slotFileRenamed(KIO::Job*,KUrl,KUrl)) );
connect(
job, SIGNAL(result(KJob*)),
this, SLOT(slotCopyFinished(KJob*))
);
connect(
job, SIGNAL(renamed(KIO::Job*,KUrl,KUrl)),
this, SLOT(slotFileRenamed(KIO::Job*,KUrl,KUrl))
);
// wait for job
job->exec();
return;
}
properties->updateUrl(properties->kurl());
// Update also relative path (for apps and mimetypes)
if ( !d->m_sRelativePath.isEmpty() )
if (!d->m_sRelativePath.isEmpty()) {
determineRelativePath(properties->kurl().toLocalFile());
}
}
// No job, keep going
slotCopyFinished(0L);
@ -1317,12 +1332,10 @@ void KFilePropsPlugin::applyChanges()
void KFilePropsPlugin::slotCopyFinished(KJob *job)
{
kDebug(250) << "KFilePropsPlugin::slotCopyFinished";
if (job)
{
if (job) {
// allow apply() to return
emit leaveModality();
if ( job->error() )
{
if (job->error()) {
job->uiDelegate()->showErrorMessage();
// Didn't work. Revert the URL to the old one
properties->updateUrl(static_cast<KIO::CopyJob*>(job)->srcUrls().first());
@ -1335,8 +1348,7 @@ void KFilePropsPlugin::slotCopyFinished( KJob * job )
Q_ASSERT(!properties->item().url().isEmpty());
// Save the file where we can -> usually in ~/.kde/...
if (d->bDesktopFile && !d->m_sRelativePath.isEmpty())
{
if (d->bDesktopFile && !d->m_sRelativePath.isEmpty()) {
kDebug(250) << "KFilePropsPlugin::slotCopyFinished " << d->m_sRelativePath;
KUrl newURL;
newURL.setPath(KDesktopFile::locateLocal(d->m_sRelativePath));
@ -1396,8 +1408,9 @@ void KFilePropsPlugin::slotCopyFinished( KJob * job )
void KFilePropsPlugin::applyIconChanges()
{
KIconButton *iconButton = qobject_cast<KIconButton*>(d->iconArea);
if ( !iconButton || !d->bIconChanged )
if (!iconButton || !d->bIconChanged) {
return;
}
// handle icon changes - only local files (or pseudo-local) for now
// TODO: Use KTempFile and KIO::file_copy with overwrite = true
KUrl url = properties->kurl();
@ -1405,14 +1418,13 @@ void KFilePropsPlugin::applyIconChanges()
if (url.isLocalFile()) {
QString path;
if (S_ISDIR(properties->item().mode()))
{
if (S_ISDIR(properties->item().mode())) {
path = url.toLocalFile(KUrl::AddTrailingSlash) + QString::fromLatin1(".directory");
// don't call updateUrl because the other tabs (i.e. permissions)
// apply to the directory, not the .directory file.
}
else
} else {
path = url.toLocalFile();
}
// Get the default image
QString str = KMimeType::findByUrl(url,

View file

@ -56,16 +56,14 @@ namespace KIO { class Job; }
class KIO_EXPORT KPropertiesDialog : public KPageDialog
{
Q_OBJECT
public:
/**
* Determine whether there are any property pages available for the
* given file items.
* @param _items the list of items to check.
* @return true if there are any property pages, otherwise false.
*/
static bool canDisplay( const KFileItemList& _items );
static bool canDisplay(const KFileItemList &items);
/**
* Brings up a Properties dialog, as shown above.
@ -78,8 +76,7 @@ public:
* @param parent is the parent of the dialog widget.
* @param name is the internal name.
*/
explicit KPropertiesDialog( const KFileItem& item,
QWidget* parent = 0 );
explicit KPropertiesDialog(const KFileItem &item, QWidget* parent = nullptr);
/**
* \overload
@ -93,8 +90,7 @@ public:
* @param parent is the parent of the dialog widget.
* @param name is the internal name.
*/
explicit KPropertiesDialog( const KFileItemList& _items,
QWidget *parent = 0 );
explicit KPropertiesDialog(const KFileItemList &items, QWidget *parent = nullptr);
/**
* Brings up a Properties dialog. Convenience constructor for
@ -112,8 +108,7 @@ public:
* For local files with a known mimetype, simply create a KFileItem and pass
* it to the other constructor.
*/
explicit KPropertiesDialog( const KUrl& _url,
QWidget* parent = 0 );
explicit KPropertiesDialog(const KUrl &url, QWidget *parent = nullptr);
/**
* Creates a properties dialog for a new .desktop file (whose name
@ -127,9 +122,8 @@ public:
* @param parent is the parent of the dialog widget.
* @param name is the internal name.
*/
KPropertiesDialog( const KUrl& _tempUrl, const KUrl& _currentDir,
const QString& _defaultName,
QWidget* parent = 0 );
KPropertiesDialog(const KUrl &tempUrl, const KUrl &currentDir,
const QString &defaultName, QWidget *parent = nullptr);
/**
* Creates an empty properties dialog (for applications that want use
@ -140,8 +134,7 @@ public:
* @param name is the internal name.
* @param modal tells the dialog whether it should be modal.
*/
explicit KPropertiesDialog(const QString& title,
QWidget* parent = 0);
explicit KPropertiesDialog(const QString &title, QWidget *parent = nullptr);
/**
* Cleans up the properties dialog and frees any associated resources,
@ -153,24 +146,18 @@ public:
/**
* Immediately displays a Properties dialog using constructor with
* the same parameters.
* On MS Windows, if @p item points to a local file, native (non modal) property
* dialog is displayed (@p parent and @p modal are ignored in this case).
*
* @return true on successful dialog displaying (can be false on win32).
* @return true on successful dialog displaying.
*/
static bool showDialog(const KFileItem& item, QWidget* parent = 0,
bool modal = true);
static bool showDialog(const KFileItem &item, QWidget *parent = nullptr, bool modal = true);
/**
* Immediately displays a Properties dialog using constructor with
* the same parameters.
* On MS Windows, if @p _url points to a local file, native (non modal) property
* dialog is displayed (@p parent and @p modal are ignored in this case).
*
* @return true on successful dialog displaying (can be false on win32).
* @return true on successful dialog displaying.
*/
static bool showDialog(const KUrl& _url, QWidget* parent = 0,
bool modal = true);
static bool showDialog(const KUrl &url, QWidget *parent = nullptr, bool modal = true);
/**
* Immediately displays a Properties dialog using constructor with
@ -181,8 +168,7 @@ public:
*
* @return true on successful dialog displaying (can be false on win32).
*/
static bool showDialog(const KFileItemList& _items, QWidget* parent = 0,
bool modal = true);
static bool showDialog(const KFileItemList &items, QWidget *parent = nullptr, bool modal = true);
/**
* Adds a "3rd party" properties plugin to the dialog. Useful
@ -245,7 +231,7 @@ public:
* Can only be called if the dialog applies to a single file or URL.
* @param _newUrl the new URL
*/
void updateUrl( const KUrl& _newUrl );
void updateUrl(const KUrl &newUrl);
/**
* Renames the item to the specified name. This can only be called if
@ -253,7 +239,7 @@ public:
* @param _name new filename, encoded.
* \see FilePropsDialogPlugin::applyChanges
*/
void rename( const QString& _name );
void rename(const QString &name);
/**
* To abort applying changes.
@ -322,6 +308,7 @@ Q_SIGNALS:
Q_SIGNALS:
void leaveModality();
private:
class KPropertiesDialogPrivate;
KPropertiesDialogPrivate* const d;
@ -352,7 +339,7 @@ public:
* To insert tabs into the properties dialog, use the add methods provided by
* KPageDialog (the properties dialog is a KPageDialog).
*/
KPropertiesDialogPlugin( KPropertiesDialog *_props );
KPropertiesDialogPlugin( KPropertiesDialog *props);
virtual ~KPropertiesDialogPlugin();
/**
@ -392,6 +379,4 @@ private:
KPropertiesDialogPluginPrivate* const d;
};
#endif
#endif // KPROPERTIESDIALOG_H

View file

@ -49,7 +49,7 @@ public:
/**
* Constructor
*/
KFilePropsPlugin( KPropertiesDialog *_props );
KFilePropsPlugin(KPropertiesDialog *props);
virtual ~KFilePropsPlugin();
/**
@ -62,7 +62,7 @@ public:
/**
* Tests whether the files specified by _items need a 'General' plugin.
*/
static bool supports( const KFileItemList& _items );
static bool supports(const KFileItemList &items);
/**
* Called after all plugins applied their changes
@ -84,6 +84,7 @@ protected Q_SLOTS:
Q_SIGNALS:
void leaveModality();
private Q_SLOTS:
void nameFileChanged(const QString &text);
void slotIconChanged();
@ -123,7 +124,7 @@ public:
/**
* Constructor
*/
KFilePermissionsPropsPlugin( KPropertiesDialog *_props );
KFilePermissionsPropsPlugin(KPropertiesDialog *props);
virtual ~KFilePermissionsPropsPlugin();
virtual void applyChanges();
@ -131,10 +132,9 @@ public:
/**
* Tests whether the file specified by _items needs a 'Permissions' plugin.
*/
static bool supports( const KFileItemList& _items );
static bool supports(const KFileItemList &items);
private Q_SLOTS:
void slotChmodResult(KJob *);
void slotShowAdvancedPermissions();
@ -178,12 +178,12 @@ public:
/**
* Constructor
*/
KUrlPropsPlugin( KPropertiesDialog *_props );
KUrlPropsPlugin(KPropertiesDialog *props);
virtual ~KUrlPropsPlugin();
virtual void applyChanges();
static bool supports( const KFileItemList& _items );
static bool supports(const KFileItemList &items);
private:
class KUrlPropsPluginPrivate;
@ -199,12 +199,12 @@ class KDevicePropsPlugin : public KPropertiesDialogPlugin
{
Q_OBJECT
public:
KDevicePropsPlugin( KPropertiesDialog *_props );
KDevicePropsPlugin(KPropertiesDialog *props);
virtual ~KDevicePropsPlugin();
virtual void applyChanges();
static bool supports( const KFileItemList& _items );
static bool supports(const KFileItemList &items);
private Q_SLOTS:
void slotActivated(int);
@ -235,12 +235,12 @@ public:
/**
* Constructor
*/
KDesktopPropsPlugin( KPropertiesDialog *_props );
KDesktopPropsPlugin( KPropertiesDialog *props);
virtual ~KDesktopPropsPlugin();
virtual void applyChanges();
static bool supports( const KFileItemList& _items );
static bool supports(const KFileItemList &items);
public Q_SLOTS:
void slotAddFiletype();