diff --git a/src/core/batchrenamejob.h b/src/core/batchrenamejob.h index 48d1596d..48bba112 100644 --- a/src/core/batchrenamejob.h +++ b/src/core/batchrenamejob.h @@ -1,89 +1,89 @@ /* This file is part of the KDE libraries Copyright (C) 2017 by Chinmoy Ranjan Pradhan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef BATCHRENAMEJOB_H #define BATCHRENAMEJOB_H #include "kiocore_export.h" #include "job_base.h" namespace KIO { class BatchRenameJobPrivate; /** * @class KIO::BatchRenameJob batchrenamejob.h * * A KIO job that renames multiple files in one go. * * @since 5.42 */ class KIOCORE_EXPORT BatchRenameJob : public Job { Q_OBJECT public: - virtual ~BatchRenameJob(); + ~BatchRenameJob() Q_DECL_OVERRIDE; Q_SIGNALS: /** * Signals that a file was renamed. */ void fileRenamed(const QUrl &oldUrl, const QUrl &newUrl); protected Q_SLOTS: void slotResult(KJob *job) Q_DECL_OVERRIDE; protected: /// @internal BatchRenameJob(BatchRenameJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotStart()) Q_DECLARE_PRIVATE(BatchRenameJob) }; /** * Renames multiple files at once. * * The new filename is obtained by replacing the characters represented by * @p placeHolder by the index @p index. * E.g. Calling batchRename({"file:///Test.jpg"}, "Test #" 12, '#') renames * the file to "Test 12.jpg". A connected sequence of placeholders results in * leading zeros. batchRename({"file:///Test.jpg"}, "Test ####" 12, '#') renames * the file to "Test 0012.jpg". And if no placeholder is there then @p index is * appended to @p newName. Calling batchRename({"file:///Test.jpg"}, "NewTest" 12, '#') * renames the file to "NewTest12.jpg". * * @param src The list of items to rename. * @param newName The base name to use in all new filenames. * @param index The integer(incremented after renaming a file) to add to the base name. * @param placeHolder The character(s) which @p index will replace. * * @return A pointer to the job handling the operation. * @since 5.42 */ KIOCORE_EXPORT BatchRenameJob *batchRename(const QList &src, const QString &newName, int index, QChar placeHolder, JobFlags flags = DefaultFlags); } #endif diff --git a/src/core/connectionserver.h b/src/core/connectionserver.h index f93f6c83..02c163f6 100644 --- a/src/core/connectionserver.h +++ b/src/core/connectionserver.h @@ -1,78 +1,78 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_CONNECTIONSERVER_H #define KIO_CONNECTIONSERVER_H #include "kiocore_export.h" #include #include namespace KIO { class ConnectionServerPrivate; class Connection; /** * @private * @internal * * This class provides a way to obtaining KIO::Connection connections. * Used by klauncher. * Do not use outside KIO and klauncher! */ class KIOCORE_EXPORT ConnectionServer : public QObject { Q_OBJECT public: - ConnectionServer(QObject *parent = nullptr); + explicit ConnectionServer(QObject *parent = nullptr); ~ConnectionServer(); /** * Sets this connection to listen mode. Use address() to obtain the * address this is listening on. */ void listenForRemote(); bool isListening() const; /// Closes the connection. void close(); /** * Returns the address for this connection if it is listening, an empty * address if not. */ QUrl address() const; Connection *nextPendingConnection(); void setNextPendingConnection(Connection *conn); Q_SIGNALS: void newConnection(); private: friend class ConnectionServerPrivate; ConnectionServerPrivate *const d; }; } // namespace KIO #endif diff --git a/src/core/copyjob.h b/src/core/copyjob.h index 0f2fff55..fb4c0b26 100644 --- a/src/core/copyjob.h +++ b/src/core/copyjob.h @@ -1,436 +1,436 @@ // -*- c++ -*- /* This file is part of the KDE libraries Copyright 2000 Stephan Kulow Copyright 2000-2006 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_COPYJOB_H #define KIO_COPYJOB_H #include #include #include #include #include "kiocore_export.h" #include // filesize_t #include "job_base.h" class QTimer; namespace KIO { /// @internal /// KF6 TODO: move to .cpp and remove aboutToCreate signal struct CopyInfo { QUrl uSource; QUrl uDest; QString linkDest; // for symlinks only int permissions; QDateTime ctime; QDateTime mtime; KIO::filesize_t size; // 0 for dirs }; class CopyJobPrivate; /** * @class KIO::CopyJob copyjob.h * * CopyJob is used to move, copy or symlink files and directories. * Don't create the job directly, but use KIO::copy(), * KIO::move(), KIO::link() and friends. * * @see KIO::copy() * @see KIO::copyAs() * @see KIO::move() * @see KIO::moveAs() * @see KIO::link() * @see KIO::linkAs() */ class KIOCORE_EXPORT CopyJob : public Job { Q_OBJECT public: /** * Defines the mode of the operation */ enum CopyMode { Copy, Move, Link }; - virtual ~CopyJob(); + ~CopyJob() Q_DECL_OVERRIDE; /** * Returns the mode of the operation (copy, move, or link), * depending on whether KIO::copy(), KIO::move() or KIO::link() was called. */ CopyMode operationMode() const; /** * Returns the list of source URLs. * @return the list of source URLs. */ QList srcUrls() const; /** * Returns the destination URL. * @return the destination URL */ QUrl destUrl() const; /** * By default the permissions of the copied files will be those of the source files. * * But when copying "template" files to "new" files, people prefer the umask * to apply, rather than the template's permissions. * For that case, call setDefaultPermissions(true) */ void setDefaultPermissions(bool b); /** * Skip copying or moving any file when the destination already exists, * instead of the default behavior (interactive mode: showing a dialog to the user, * non-interactive mode: aborting with an error). * Initially added for a unit test. * \since 4.2 */ void setAutoSkip(bool autoSkip); /** * Rename files automatically when the destination already exists, * instead of the default behavior (interactive mode: showing a dialog to the user, * non-interactive mode: aborting with an error). * Initially added for a unit test. * \since 4.7 */ void setAutoRename(bool autoRename); /** * Reuse any directory that already exists, instead of the default behavior * (interactive mode: showing a dialog to the user, * non-interactive mode: aborting with an error). * \since 4.2 */ void setWriteIntoExistingDirectories(bool overwriteAllDirs); /** * Reimplemented for internal reasons */ bool doSuspend() Q_DECL_OVERRIDE; /** * Reimplemented for internal reasons */ bool doResume() Q_DECL_OVERRIDE; Q_SIGNALS: /** * Emitted when the total number of files is known. * @param job the job that emitted this signal * @param files the total number of files */ void totalFiles(KJob *job, unsigned long files); /** * Emitted when the toal number of direcotries is known. * @param job the job that emitted this signal * @param dirs the total number of directories */ void totalDirs(KJob *job, unsigned long dirs); /** * Emitted when it is known which files / directories are going * to be created. Note that this may still change e.g. when * existing files with the same name are discovered. * @param job the job that emitted this signal * @param files a list of items that are about to be created. * @deprecated since 5.2 -- this signal is unused since kde 3... */ QT_MOC_COMPAT void aboutToCreate(KIO::Job *job, const QList &files); /** * Sends the number of processed files. * @param job the job that emitted this signal * @param files the number of processed files */ void processedFiles(KIO::Job *job, unsigned long files); /** * Sends the number of processed directories. * @param job the job that emitted this signal * @param dirs the number of processed dirs */ void processedDirs(KIO::Job *job, unsigned long dirs); /** * The job is copying a file or directory. * * Note: This signal is used for progress dialogs, it's not emitted for * every file or directory (this would be too slow), but every 200ms. * * @param job the job that emitted this signal * @param src the URL of the file or directory that is currently * being copied * @param dest the destination of the current operation */ void copying(KIO::Job *job, const QUrl &src, const QUrl &dest); /** * The job is creating a symbolic link. * * Note: This signal is used for progress dialogs, it's not emitted for * every file or directory (this would be too slow), but every 200ms. * * @param job the job that emitted this signal * @param target the URL of the file or directory that is currently * being linked * @param to the destination of the current operation */ void linking(KIO::Job *job, const QString &target, const QUrl &to); /** * The job is moving a file or directory. * * Note: This signal is used for progress dialogs, it's not emitted for * every file or directory (this would be too slow), but every 200ms. * * @param job the job that emitted this signal * @param from the URL of the file or directory that is currently * being moved * @param to the destination of the current operation */ void moving(KIO::Job *job, const QUrl &from, const QUrl &to); /** * The job is creating the directory @p dir. * * This signal is emitted for every directory being created. * * @param job the job that emitted this signal * @param dir the directory that is currently being created */ void creatingDir(KIO::Job *job, const QUrl &dir); /** * The user chose to rename @p from to @p to. * * @param job the job that emitted this signal * @param from the original name * @param to the new name */ void renamed(KIO::Job *job, const QUrl &from, const QUrl &to); /** * The job emits this signal when copying or moving a file or directory successfully finished. * This signal is mainly for the Undo feature. * If you simply want to know when a copy job is done, use result(). * * @param job the job that emitted this signal * @param from the source URL * @param to the destination URL * @param mtime the modification time of the source file, hopefully set on the destination file * too (when the kioslave supports it). * @param directory indicates whether a file or directory was successfully copied/moved. * true for a directory, false for file * @param renamed indicates that the destination URL was created using a * rename operation (i.e. fast directory moving). true if is has been renamed */ void copyingDone(KIO::Job *job, const QUrl &from, const QUrl &to, const QDateTime &mtime, bool directory, bool renamed); /** * The job is copying or moving a symbolic link, that points to target. * The new link is created in @p to. The existing one is/was in @p from. * This signal is mainly for the Undo feature. * @param job the job that emitted this signal * @param from the source URL * @param target the target * @param to the destination URL */ void copyingLinkDone(KIO::Job *job, const QUrl &from, const QString &target, const QUrl &to); protected Q_SLOTS: void slotResult(KJob *job) Q_DECL_OVERRIDE; protected: CopyJob(CopyJobPrivate &dd); void emitResult(); private: Q_PRIVATE_SLOT(d_func(), void slotStart()) Q_PRIVATE_SLOT(d_func(), void slotEntries(KIO::Job *, const KIO::UDSEntryList &list)) Q_PRIVATE_SLOT(d_func(), void slotSubError(KIO::ListJob *, KIO::ListJob *)) Q_PRIVATE_SLOT(d_func(), void slotProcessedSize(KJob *, qulonglong data_size)) Q_PRIVATE_SLOT(d_func(), void slotTotalSize(KJob *, qulonglong size)) Q_PRIVATE_SLOT(d_func(), void slotReport()) Q_PRIVATE_SLOT(d_func(), void sourceStated(const KIO::UDSEntry &entry, const QUrl &sourceUrl)) Q_DECLARE_PRIVATE(CopyJob) }; /** * Copy a file or directory @p src into the destination @p dest, * which can be a file (including the final filename) or a directory * (into which @p src will be copied). * * This emulates the cp command completely. * * @param src the file or directory to copy * @param dest the destination * @param flags copy() supports HideProgressInfo and Overwrite. * Note: Overwrite has the meaning of both "write into existing directories" and * "overwrite existing files". However if "dest" exists, then src is copied * into a subdir of dest, just like "cp" does. Use copyAs if you don't want that. * * @return the job handling the operation * @see copyAs() */ KIOCORE_EXPORT CopyJob *copy(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Copy a file or directory @p src into the destination @p dest, * which is the destination name in any case, even for a directory. * * As opposed to copy(), this doesn't emulate cp, but is the only * way to copy a directory, giving it a new name and getting an error * box if a directory already exists with the same name (or writing the * contents of @p src into @p dest, when using Overwrite). * * @param src the file or directory to copy * @param dest the destination * @param flags copyAs() supports HideProgressInfo and Overwrite. * Note: Overwrite has the meaning of both "write into existing directories" and * "overwrite existing files". * * * @return the job handling the operation */ KIOCORE_EXPORT CopyJob *copyAs(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Copy a list of file/dirs @p src into a destination directory @p dest. * * @param src the list of files and/or directories * @param dest the destination * @param flags copy() supports HideProgressInfo and Overwrite. * Note: Overwrite has the meaning of both "write into existing directories" and * "overwrite existing files". However if "dest" exists, then src is copied * into a subdir of dest, just like "cp" does. * @return the job handling the operation */ KIOCORE_EXPORT CopyJob *copy(const QList &src, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Moves a file or directory @p src to the given destination @p dest. * * @param src the file or directory to copy * @param dest the destination * @param flags move() supports HideProgressInfo and Overwrite. * Note: Overwrite has the meaning of both "write into existing directories" and * "overwrite existing files". However if "dest" exists, then src is copied * into a subdir of dest, just like "cp" does. * @return the job handling the operation * @see copy() * @see moveAs() */ KIOCORE_EXPORT CopyJob *move(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Moves a file or directory @p src to the given destination @p dest. Unlike move() * this operation will not move @p src into @p dest when @p dest exists: it will * either fail, or move the contents of @p src into it if Overwrite is set. * * @param src the file or directory to copy * @param dest the destination * @param flags moveAs() supports HideProgressInfo and Overwrite. * Note: Overwrite has the meaning of both "write into existing directories" and * "overwrite existing files". * @return the job handling the operation * @see copyAs() */ KIOCORE_EXPORT CopyJob *moveAs(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Moves a list of files or directories @p src to the given destination @p dest. * * @param src the list of files or directories to copy * @param dest the destination * @param flags move() supports HideProgressInfo and Overwrite. * Note: Overwrite has the meaning of both "write into existing directories" and * "overwrite existing files". However if "dest" exists, then src is copied * into a subdir of dest, just like "cp" does. * @return the job handling the operation * @see copy() */ KIOCORE_EXPORT CopyJob *move(const QList &src, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Create a link. * If the protocols and hosts are the same, a Unix symlink will be created. * Otherwise, a .desktop file of Type Link and pointing to the src URL will be created. * * @param src The existing file or directory, 'target' of the link. * @param destDir Destination directory where the link will be created. * @param flags link() supports HideProgressInfo only * @return the job handling the operation */ KIOCORE_EXPORT CopyJob *link(const QUrl &src, const QUrl &destDir, JobFlags flags = DefaultFlags); /** * Create several links * If the protocols and hosts are the same, a Unix symlink will be created. * Otherwise, a .desktop file of Type Link and pointing to the src URL will be created. * * @param src The existing files or directories, 'targets' of the link. * @param destDir Destination directory where the links will be created. * @param flags link() supports HideProgressInfo only * @return the job handling the operation * @see link() */ KIOCORE_EXPORT CopyJob *link(const QList &src, const QUrl &destDir, JobFlags flags = DefaultFlags); /** * Create a link. Unlike link() this operation will fail when @p dest is an existing * directory rather than the final name for the link. * If the protocols and hosts are the same, a Unix symlink will be created. * Otherwise, a .desktop file of Type Link and pointing to the src URL will be created. * * @param src The existing file or directory, 'target' of the link. * @param dest Destination (i.e. the final symlink) * @param flags linkAs() supports HideProgressInfo only * @return the job handling the operation * @see link () * @see copyAs() */ KIOCORE_EXPORT CopyJob *linkAs(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Trash a file or directory. * This is currently only supported for local files and directories. * Use QUrl::fromLocalFile to create a URL from a local file path. * * @param src file to delete * @param flags trash() supports HideProgressInfo only * @return the job handling the operation */ KIOCORE_EXPORT CopyJob *trash(const QUrl &src, JobFlags flags = DefaultFlags); /** * Trash a list of files or directories. * This is currently only supported for local files and directories. * * @param src the files to delete * @param flags trash() supports HideProgressInfo only * @return the job handling the operation */ KIOCORE_EXPORT CopyJob *trash(const QList &src, JobFlags flags = DefaultFlags); } #endif diff --git a/src/core/dataslave_p.h b/src/core/dataslave_p.h index 68bf77f3..d5c5e439 100644 --- a/src/core/dataslave_p.h +++ b/src/core/dataslave_p.h @@ -1,127 +1,127 @@ // -*- c++ -*- /* * This file is part of the KDE libraries * Copyright (c) 2003 Leo Savernik * Derived from slave.h * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. **/ #ifndef KIO_DATASLAVE_H #define KIO_DATASLAVE_H #include "global.h" #include "slave.h" class QTimer; // don't forget to sync DISPATCH_IMPL in dataslave_p.h #define DISPATCH_DECL(type) \ void dispatch_##type(); // don't forget to sync DISPATCH_IMPL1 in dataslave_p.h #define DISPATCH_DECL1(type, paramtype, param) \ void dispatch_##type(paramtype param); namespace KIO { /** * This class provides a high performance implementation for the data * url scheme (rfc2397). * * @internal * Do not use this class in external applications. It is an implementation * detail of KIO and subject to change without notice. * @author Leo Savernik */ class DataSlave : public KIO::Slave { Q_OBJECT public: DataSlave(); - virtual ~DataSlave(); + ~DataSlave() Q_DECL_OVERRIDE; virtual void setHost(const QString &host, quint16 port, const QString &user, const QString &passwd) Q_DECL_OVERRIDE; void setConfig(const MetaData &config) Q_DECL_OVERRIDE; void suspend() Q_DECL_OVERRIDE; void resume() Q_DECL_OVERRIDE; bool suspended() Q_DECL_OVERRIDE; void send(int cmd, const QByteArray &arr = QByteArray()) Q_DECL_OVERRIDE; void hold(const QUrl &url) Q_DECL_OVERRIDE; // pure virtual methods that are defined by the actual protocol virtual void get(const QUrl &url) = 0; virtual void mimetype(const QUrl &url) = 0; protected: /** * Sets metadata * @internal */ void setAllMetaData(const MetaData &); /** * Sends metadata set with setAllMetaData * @internal */ void sendMetaData(); // queuing methods /** identifiers of functions to be queued */ enum QueueType { Queue_mimeType = 1, Queue_totalSize, Queue_sendMetaData, Queue_data, Queue_finished }; /** structure for queuing. It is very primitive, it doesn't * even try to conserve memory. */ struct QueueStruct { QueueType type; QString s; KIO::filesize_t size; QByteArray ba; QueueStruct() {} QueueStruct(QueueType type) : type(type) {} }; typedef QList DispatchQueue; DispatchQueue dispatchQueue; DISPATCH_DECL1(mimeType, const QString &, s) DISPATCH_DECL1(totalSize, KIO::filesize_t, size) DISPATCH_DECL(sendMetaData) DISPATCH_DECL1(data, const QByteArray &, ba) DISPATCH_DECL(finished) protected Q_SLOTS: /** dispatches next queued method. Does nothing if there are no * queued methods. */ void dispatchNext(); private: MetaData meta_data; bool _suspended; QTimer *timer; }; } #undef DISPATCH_DECL #undef DISPATCH_DECL1 #endif diff --git a/src/core/deletejob.h b/src/core/deletejob.h index 86a612f2..a1b46633 100644 --- a/src/core/deletejob.h +++ b/src/core/deletejob.h @@ -1,127 +1,127 @@ // -*- c++ -*- /* This file is part of the KDE libraries Copyright 2000 Stephan Kulow Copyright 2000-2006 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_DELETEJOB_H #define KIO_DELETEJOB_H #include #include "kiocore_export.h" #include "global.h" #include "job_base.h" class QTimer; namespace KIO { class DeleteJobPrivate; /** * @class KIO::DeleteJob deletejob.h * * A more complex Job to delete files and directories. * Don't create the job directly, but use KIO::del() instead. * * @see KIO::del() */ class KIOCORE_EXPORT DeleteJob : public Job { Q_OBJECT public: - virtual ~DeleteJob(); + ~DeleteJob() Q_DECL_OVERRIDE; /** * Returns the list of URLs. * @return the list of URLs. */ QList urls() const; Q_SIGNALS: /** * Emitted when the total number of files is known. * @param job the job that emitted this signal * @param files the total number of files */ void totalFiles(KJob *job, unsigned long files); /** * Emitted when the toal number of direcotries is known. * @param job the job that emitted this signal * @param dirs the total number of directories */ void totalDirs(KJob *job, unsigned long dirs); /** * Sends the number of processed files. * @param job the job that emitted this signal * @param files the number of processed files */ void processedFiles(KIO::Job *job, unsigned long files); /** * Sends the number of processed directories. * @param job the job that emitted this signal * @param dirs the number of processed dirs */ void processedDirs(KIO::Job *job, unsigned long dirs); /** * Sends the URL of the file that is currently being deleted. * @param job the job that emitted this signal * @param file the URL of the file or directory that is being * deleted */ void deleting(KIO::Job *job, const QUrl &file); protected Q_SLOTS: void slotResult(KJob *job) Q_DECL_OVERRIDE; protected: DeleteJob(DeleteJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotStart()) Q_PRIVATE_SLOT(d_func(), void slotEntries(KIO::Job *, const KIO::UDSEntryList &list)) Q_PRIVATE_SLOT(d_func(), void slotReport()) Q_DECLARE_PRIVATE(DeleteJob) }; /** * Delete a file or directory. * * @param src file to delete * @param flags We support HideProgressInfo here * @return the job handling the operation */ KIOCORE_EXPORT DeleteJob *del(const QUrl &src, JobFlags flags = DefaultFlags); /** * Deletes a list of files or directories. * * @param src the files to delete * @param flags We support HideProgressInfo here * @return the job handling the operation */ KIOCORE_EXPORT DeleteJob *del(const QList &src, JobFlags flags = DefaultFlags); } #endif diff --git a/src/core/directorysizejob.h b/src/core/directorysizejob.h index 9d46894d..51915701 100644 --- a/src/core/directorysizejob.h +++ b/src/core/directorysizejob.h @@ -1,100 +1,100 @@ /* This file is part of the KDE libraries Copyright (C) 2000, 2006 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef DIRECTORYSIZEJOB_H #define DIRECTORYSIZEJOB_H #include "kiocore_export.h" #include "job_base.h" #include namespace KIO { class DirectorySizeJobPrivate; /** * @class KIO::DirectorySizeJob directorysizejob.h * * Computes a directory size (similar to "du", but doesn't give the same results * since we simply sum up the dir and file sizes, whereas du speaks disk blocks) * * Usage: see KIO::directorySize. */ class KIOCORE_EXPORT DirectorySizeJob : public KIO::Job { Q_OBJECT public: - ~DirectorySizeJob(); + ~DirectorySizeJob() Q_DECL_OVERRIDE; public: /** * @return the size we found */ KIO::filesize_t totalSize() const; /** * @return the total number of files (counting symlinks to files, sockets * and character devices as files) in this directory and all sub-directories */ KIO::filesize_t totalFiles() const; /** * @return the total number of sub-directories found (not including the * directory the search started from and treating symlinks to directories * as directories) */ KIO::filesize_t totalSubdirs() const; protected Q_SLOTS: void slotResult(KJob *job) Q_DECL_OVERRIDE; protected: DirectorySizeJob(DirectorySizeJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotEntries(KIO::Job *, const KIO::UDSEntryList &)) Q_PRIVATE_SLOT(d_func(), void processNextItem()) Q_DECLARE_PRIVATE(DirectorySizeJob) }; /** * Computes a directory size (by doing a recursive listing). * Connect to the result signal (this is the preferred solution to avoid blocking the GUI), * or use exec() for a synchronous (blocking) calculation. * * This one lists a single directory. */ KIOCORE_EXPORT DirectorySizeJob *directorySize(const QUrl &directory); /** * Computes a directory size (by doing a recursive listing). * Connect to the result signal (this is the preferred solution to avoid blocking the GUI), * or use exec() for a synchronous (blocking) calculation. * * This one lists the items from @p lstItems. * The reason we asks for items instead of just urls, is so that * we directly know if the item is a file or a directory, * and in case of a file, we already have its size. */ KIOCORE_EXPORT DirectorySizeJob *directorySize(const KFileItemList &lstItems); } #endif diff --git a/src/core/emptytrashjob.h b/src/core/emptytrashjob.h index 3f58be5c..7105b2d8 100644 --- a/src/core/emptytrashjob.h +++ b/src/core/emptytrashjob.h @@ -1,66 +1,66 @@ /* This file is part of the KDE libraries Copyright (C) 2014 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EMPTYTRASHJOB_H #define EMPTYTRASHJOB_H #include "kiocore_export.h" #include "simplejob.h" namespace KIO { class EmptyTrashJobPrivate; /** * @class KIO::EmptyTrashJob emptytrashjob.h * * A KIO job for emptying the trash * @see KIO::trash() * @see KIO::restoreFromTrash() * @since 5.2 */ class KIOCORE_EXPORT EmptyTrashJob : public SimpleJob { Q_OBJECT public: - ~EmptyTrashJob(); + ~EmptyTrashJob() Q_DECL_OVERRIDE; protected: void slotFinished() Q_DECL_OVERRIDE; private: EmptyTrashJob(EmptyTrashJobPrivate &dd); private: Q_DECLARE_PRIVATE(EmptyTrashJob) }; /** * Empties the trash. * * @return A pointer to the job handling the operation. * @since 5.2 */ KIOCORE_EXPORT EmptyTrashJob *emptyTrash(); } #endif diff --git a/src/core/filecopyjob.h b/src/core/filecopyjob.h index e87d44e4..00b415c6 100644 --- a/src/core/filecopyjob.h +++ b/src/core/filecopyjob.h @@ -1,157 +1,157 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2009 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_FILECOPYJOB_H #define KIO_FILECOPYJOB_H #include "job_base.h" #include // filesize_t namespace KIO { class FileCopyJobPrivate; /** * @class KIO::FileCopyJob filecopyjob.h * * The FileCopyJob copies data from one place to another. * @see KIO::file_copy() * @see KIO::file_move() */ class KIOCORE_EXPORT FileCopyJob : public Job { Q_OBJECT public: - ~FileCopyJob(); + ~FileCopyJob() Q_DECL_OVERRIDE; /** * If you know the size of the source file, call this method * to inform this job. It will be displayed in the "resume" dialog. * @param size the size of the source file */ void setSourceSize(KIO::filesize_t size); /** * Sets the modification time of the file * * Note that this is ignored if a direct copy (SlaveBase::copy) can be done, * in which case the mtime of the source is applied to the destination (if the protocol * supports the concept). */ void setModificationTime(const QDateTime &mtime); /** * Returns the source URL. * @return the source URL */ QUrl srcUrl() const; /** * Returns the destination URL. * @return the destination URL */ QUrl destUrl() const; bool doSuspend() Q_DECL_OVERRIDE; bool doResume() Q_DECL_OVERRIDE; Q_SIGNALS: /** * Mimetype determined during a file copy. * This is never emitted during a move, and might not be emitted during * a file copy, depending on the slave. But when a get and a put are * being used (which is the common case), this signal forwards the * mimetype information from the get job. * * @param job the job that emitted this signal * @param type the mime type */ void mimetype(KIO::Job *job, const QString &type); protected Q_SLOTS: /** * Called whenever a subjob finishes. * @param job the job that emitted this signal */ void slotResult(KJob *job) Q_DECL_OVERRIDE; protected: FileCopyJob(FileCopyJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotStart()) Q_PRIVATE_SLOT(d_func(), void slotData(KIO::Job *, const QByteArray &data)) Q_PRIVATE_SLOT(d_func(), void slotDataReq(KIO::Job *, QByteArray &data)) Q_PRIVATE_SLOT(d_func(), void slotMimetype(KIO::Job *, const QString &type)) Q_PRIVATE_SLOT(d_func(), void slotProcessedSize(KJob *job, qulonglong size)) Q_PRIVATE_SLOT(d_func(), void slotTotalSize(KJob *job, qulonglong size)) Q_PRIVATE_SLOT(d_func(), void slotPercent(KJob *job, unsigned long pct)) Q_PRIVATE_SLOT(d_func(), void slotCanResume(KIO::Job *job, KIO::filesize_t offset)) Q_DECLARE_PRIVATE(FileCopyJob) }; /** * Copy a single file. * * Uses either SlaveBase::copy() if the slave supports that * or get() and put() otherwise. * @param src Where to get the file. * @param dest Where to put the file. * @param permissions May be -1. In this case no special permission mode is set. * @param flags Can be HideProgressInfo, Overwrite and Resume here. WARNING: * Setting Resume means that the data will be appended to @p dest if @p dest exists. * @return the job handling the operation. */ KIOCORE_EXPORT FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags); /** * Overload for catching code mistakes. Do NOT call this method (it is not implemented), * insert a value for permissions (-1 by default) before the JobFlags. * @since 4.5 */ FileCopyJob *file_copy(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose. /** * Move a single file. * * Use either SlaveBase::rename() if the slave supports that, * or copy() and del() otherwise, or eventually get() & put() & del() * @param src Where to get the file. * @param dest Where to put the file. * @param permissions May be -1. In this case no special permission mode is set. * @param flags Can be HideProgressInfo, Overwrite and Resume here. WARNING: * Setting Resume means that the data will be appended to @p dest if @p dest exists. * @return the job handling the operation. */ KIOCORE_EXPORT FileCopyJob *file_move(const QUrl &src, const QUrl &dest, int permissions = -1, JobFlags flags = DefaultFlags); /** * Overload for catching code mistakes. Do NOT call this method (it is not implemented), * insert a value for permissions (-1 by default) before the JobFlags. * @since 4.3 */ FileCopyJob *file_move(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_EQ_DELETE; // not implemented - on purpose. } #endif diff --git a/src/core/filesystemfreespacejob.h b/src/core/filesystemfreespacejob.h index a593a4dd..573aafcc 100644 --- a/src/core/filesystemfreespacejob.h +++ b/src/core/filesystemfreespacejob.h @@ -1,75 +1,75 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2009 David Faure 2014 Mathias Tillman This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef FILESYSTEMFREESPACEJOB_H #define FILESYSTEMFREESPACEJOB_H #include "kiocore_export.h" #include "simplejob.h" namespace KIO { class FileSystemFreeSpaceJobPrivate; /** * @class KIO::FileSystemFreeSpaceJob filesystemfreespacejob.h * * A KIO job that retrieves the total and available size of a filesystem. * @since 5.3 */ class KIOCORE_EXPORT FileSystemFreeSpaceJob : public SimpleJob { Q_OBJECT public: - ~FileSystemFreeSpaceJob(); + ~FileSystemFreeSpaceJob() Q_DECL_OVERRIDE; Q_SIGNALS: /** * Signals the result * @param job the job that is redirected * @param size total amount of space * @param available amount of free space */ void result(KIO::Job *job, KIO::filesize_t size, KIO::filesize_t available); protected Q_SLOTS: void slotFinished() Q_DECL_OVERRIDE; public: FileSystemFreeSpaceJob(FileSystemFreeSpaceJobPrivate &dd); private: Q_DECLARE_PRIVATE(FileSystemFreeSpaceJob) }; /** * Get a filesystem's total and available space. * * @param url Url to the filesystem. * @return the job handling the operation. */ KIOCORE_EXPORT FileSystemFreeSpaceJob *fileSystemFreeSpace(const QUrl &url); } #endif /* FILESYSTEMFREESPACEJOB_H */ diff --git a/src/core/forwardingslavebase.h b/src/core/forwardingslavebase.h index 30b54347..51513583 100644 --- a/src/core/forwardingslavebase.h +++ b/src/core/forwardingslavebase.h @@ -1,194 +1,194 @@ /* This file is part of the KDE project Copyright (c) 2004 Kevin Ottens This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _FORWARDING_SLAVE_BASE_H_ #define _FORWARDING_SLAVE_BASE_H_ #include "kiocore_export.h" #include #include "job_base.h" // JobFlags #include #include namespace KIO { class ForwardingSlaveBasePrivate; /** * @class KIO::ForwardingSlaveBase forwardingslavebase.h * * This class should be used as a base for ioslaves acting as a * forwarder to other ioslaves. It has been designed to support only * local filesystem like ioslaves. * * If the resulting ioslave should be a simple proxy, you only need * to implement the ForwardingSlaveBase::rewriteUrl() method. * * For more advanced behavior, the classic ioslave methods should * be reimplemented, because their default behavior in this class * is to forward using the ForwardingSlaveBase::rewriteUrl() method. * * A possible code snippet for an advanced stat() behavior would look * like this in the child class: * * \code * void ChildProtocol::stat(const QUrl &url) * { * bool is_special = false; * * // Process the URL to see if it should have * // a special treatment * * if ( is_special ) * { * // Handle the URL ourselves * KIO::UDSEntry entry; * // Fill entry with UDSAtom instances * statEntry(entry); * finished(); * } * else * { * // Setup the ioslave internal state if * // required by ChildProtocol::rewriteUrl() * ForwardingSlaveBase::stat(url); * } * } * \endcode * * Of course in this case, you surely need to reimplement listDir() * and get() accordingly. * * If you want view on directories to be correctly refreshed when * something changes on a forwarded URL, you'll need a companion kded * module to emit the KDirNotify Files*() D-Bus signals. * * This class was initially used for media:/ ioslave. This ioslave code * and the MediaDirNotify class of its companion kded module can be a * good source of inspiration. * * @see ForwardingSlaveBase::rewriteUrl() * @author Kevin Ottens */ class KIOCORE_EXPORT ForwardingSlaveBase : public QObject, public SlaveBase { Q_OBJECT public: ForwardingSlaveBase(const QByteArray &protocol, const QByteArray &poolSocket, const QByteArray &appSocket); - virtual ~ForwardingSlaveBase(); + ~ForwardingSlaveBase() Q_DECL_OVERRIDE; void get(const QUrl &url) Q_DECL_OVERRIDE; void put(const QUrl &url, int permissions, JobFlags flags) Q_DECL_OVERRIDE; void stat(const QUrl &url) Q_DECL_OVERRIDE; void mimetype(const QUrl &url) Q_DECL_OVERRIDE; void listDir(const QUrl &url) Q_DECL_OVERRIDE; void mkdir(const QUrl &url, int permissions) Q_DECL_OVERRIDE; void rename(const QUrl &src, const QUrl &dest, JobFlags flags) Q_DECL_OVERRIDE; void symlink(const QString &target, const QUrl &dest, JobFlags flags) Q_DECL_OVERRIDE; void chmod(const QUrl &url, int permissions) Q_DECL_OVERRIDE; void setModificationTime(const QUrl &url, const QDateTime &mtime) Q_DECL_OVERRIDE; void copy(const QUrl &src, const QUrl &dest, int permissions, JobFlags flags) Q_DECL_OVERRIDE; void del(const QUrl &url, bool isfile) Q_DECL_OVERRIDE; protected: /** * Rewrite an url to its forwarded counterpart. It should return * true if everything was ok, and false otherwise. * * If a problem is detected it's up to this method to trigger error() * before returning. Returning false silently cancels the current * slave operation. * * @param url The URL as given during the slave call * @param newURL The new URL to forward the slave call to * @return true if the given url could be correctly rewritten */ virtual bool rewriteUrl(const QUrl &url, QUrl &newURL) = 0; /** * Allow to modify a UDSEntry before it's sent to the ioslave endpoint. * This is the default implementation working in most cases, but sometimes * you could make use of more forwarding black magic (for example * dynamically transform any desktop file into a fake directory...) * * @param entry the UDSEntry to post-process * @param listing indicate if this entry it created during a listDir * operation */ virtual void prepareUDSEntry(KIO::UDSEntry &entry, bool listing = false) const; /** * Return the URL being processed by the ioslave * Only access it inside prepareUDSEntry() */ QUrl processedUrl() const; /** * Return the URL asked to the ioslave * Only access it inside prepareUDSEntry() */ QUrl requestedUrl() const; private: // KIO::Job Q_PRIVATE_SLOT(d, void _k_slotResult(KJob *job)) Q_PRIVATE_SLOT(d, void _k_slotWarning(KJob *job, const QString &msg)) Q_PRIVATE_SLOT(d, void _k_slotInfoMessage(KJob *job, const QString &msg)) Q_PRIVATE_SLOT(d, void _k_slotTotalSize(KJob *job, qulonglong size)) Q_PRIVATE_SLOT(d, void _k_slotProcessedSize(KJob *job, qulonglong size)) Q_PRIVATE_SLOT(d, void _k_slotSpeed(KJob *job, unsigned long bytesPerSecond)) // KIO::SimpleJob subclasses Q_PRIVATE_SLOT(d, void _k_slotRedirection(KIO::Job *job, const QUrl &url)) // KIO::ListJob Q_PRIVATE_SLOT(d, void _k_slotEntries(KIO::Job *job, const KIO::UDSEntryList &entries)) // KIO::TransferJob Q_PRIVATE_SLOT(d, void _k_slotData(KIO::Job *job, const QByteArray &data)) Q_PRIVATE_SLOT(d, void _k_slotDataReq(KIO::Job *job, QByteArray &data)) Q_PRIVATE_SLOT(d, void _k_slotMimetype(KIO::Job *job, const QString &type)) Q_PRIVATE_SLOT(d, void _k_slotCanResume(KIO::Job *job, KIO::filesize_t offset)) friend class ForwardingSlaveBasePrivate; ForwardingSlaveBasePrivate *const d; }; } #endif diff --git a/src/core/hostinfo.cpp b/src/core/hostinfo.cpp index 69f83b61..d85ef738 100644 --- a/src/core/hostinfo.cpp +++ b/src/core/hostinfo.cpp @@ -1,400 +1,400 @@ /* Copyright 2008 Roland Harnau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "hostinfo.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef Q_OS_UNIX # include # include # include # include // for _PATH_RESCONF # ifndef _PATH_RESCONF # define _PATH_RESCONF "/etc/resolv.conf" # endif #endif #define TTL 300 namespace KIO { class HostInfoAgentPrivate : public QObject { Q_OBJECT public: HostInfoAgentPrivate(int cacheSize = 100); virtual ~HostInfoAgentPrivate() {} void lookupHost(const QString &hostName, QObject *receiver, const char *member); QHostInfo lookupCachedHostInfoFor(const QString &hostName); void cacheLookup(const QHostInfo &); void setCacheSize(int s) { dnsCache.setMaxCost(s); } void setTTL(int _ttl) { ttl = _ttl; } private Q_SLOTS: void queryFinished(const QHostInfo &); private: class Result; class Query; QHash openQueries; QCache > dnsCache; QDateTime resolvConfMTime; int ttl; }; class HostInfoAgentPrivate::Result : public QObject { Q_OBJECT Q_SIGNALS: void result(QHostInfo); private: friend class HostInfoAgentPrivate; }; class HostInfoAgentPrivate::Query : public QObject { Q_OBJECT public: Query(): m_watcher(), m_hostName() { connect(&m_watcher, SIGNAL(finished()), this, SLOT(relayFinished())); } void start(const QString &hostName) { m_hostName = hostName; QFuture future = QtConcurrent::run(&QHostInfo::fromName, hostName); m_watcher.setFuture(future); } QString hostName() const { return m_hostName; } Q_SIGNALS: void result(QHostInfo); private Q_SLOTS: void relayFinished() { emit result(m_watcher.result()); } private: QFutureWatcher m_watcher; QString m_hostName; }; class NameLookupThreadRequest { public: NameLookupThreadRequest(const QString &hostName) : m_hostName(hostName) { } QSemaphore *semaphore() { return &m_semaphore; } QHostInfo result() const { return m_hostInfo; } void setResult(const QHostInfo &hostInfo) { m_hostInfo = hostInfo; } QString hostName() const { return m_hostName; } int lookupId() const { return m_lookupId; } void setLookupId(int id) { m_lookupId = id; } private: Q_DISABLE_COPY(NameLookupThreadRequest) QString m_hostName; QSemaphore m_semaphore; QHostInfo m_hostInfo; int m_lookupId; }; } Q_DECLARE_METATYPE(QSharedPointer) namespace KIO { class NameLookUpThreadWorker : public QObject { Q_OBJECT public Q_SLOTS: void lookupHost(const QSharedPointer &request) { const QString hostName = request->hostName(); const int lookupId = QHostInfo::lookupHost(hostName, this, SLOT(lookupFinished(QHostInfo))); request->setLookupId(lookupId); m_lookups.insert(lookupId, request); } void abortLookup(const QSharedPointer &request) { QHostInfo::abortHostLookup(request->lookupId()); m_lookups.remove(request->lookupId()); } void lookupFinished(const QHostInfo &hostInfo) { QMap >::iterator it = m_lookups.find(hostInfo.lookupId()); if (it != m_lookups.end()) { (*it)->setResult(hostInfo); (*it)->semaphore()->release(); m_lookups.erase(it); } } private: QMap > m_lookups; }; class NameLookUpThread : public QThread { Q_OBJECT public: NameLookUpThread() : m_worker(nullptr) { qRegisterMetaType< QSharedPointer > (); start(); } - ~NameLookUpThread() + ~NameLookUpThread() Q_DECL_OVERRIDE { quit(); wait(); } NameLookUpThreadWorker *worker() { return m_worker; } QSemaphore *semaphore() { return &m_semaphore; } void run() Q_DECL_OVERRIDE { NameLookUpThreadWorker worker; m_worker = &worker; m_semaphore.release(); exec(); } private: NameLookUpThreadWorker *m_worker; QSemaphore m_semaphore; }; } using namespace KIO; Q_GLOBAL_STATIC(HostInfoAgentPrivate, hostInfoAgentPrivate) Q_GLOBAL_STATIC(NameLookUpThread, nameLookUpThread) void HostInfo::lookupHost(const QString &hostName, QObject *receiver, const char *member) { hostInfoAgentPrivate()->lookupHost(hostName, receiver, member); } QHostInfo HostInfo::lookupHost(const QString &hostName, unsigned long timeout) { // Do not perform a reverse lookup here... QHostAddress address(hostName); QHostInfo hostInfo; if (!address.isNull()) { QList addressList; addressList << address; hostInfo.setAddresses(addressList); return hostInfo; } // Look up the name in the KIO/KHTML DNS cache... hostInfo = HostInfo::lookupCachedHostInfoFor(hostName); if (!hostInfo.hostName().isEmpty() && hostInfo.error() == QHostInfo::NoError) { return hostInfo; } // Failing all of the above, do the lookup... QSharedPointer request = QSharedPointer(new NameLookupThreadRequest(hostName)); nameLookUpThread()->semaphore()->acquire(); nameLookUpThread()->semaphore()->release(); QMetaObject::invokeMethod(nameLookUpThread()->worker(), "lookupHost", Qt::QueuedConnection, Q_ARG(QSharedPointer, request)); if (request->semaphore()->tryAcquire(1, timeout)) { hostInfo = request->result(); if (!hostInfo.hostName().isEmpty() && hostInfo.error() == QHostInfo::NoError) { HostInfo::cacheLookup(hostInfo); // cache the look up... } } else { QMetaObject::invokeMethod(nameLookUpThread()->worker(), "abortLookup", Qt::QueuedConnection, Q_ARG(QSharedPointer, request)); } //qDebug() << "Name look up succeeded for" << hostName; return hostInfo; } QHostInfo HostInfo::lookupCachedHostInfoFor(const QString &hostName) { return hostInfoAgentPrivate()->lookupCachedHostInfoFor(hostName); } void HostInfo::cacheLookup(const QHostInfo &info) { hostInfoAgentPrivate()->cacheLookup(info); } void HostInfo::prefetchHost(const QString &hostName) { hostInfoAgentPrivate()->lookupHost(hostName, nullptr, nullptr); } void HostInfo::setCacheSize(int s) { hostInfoAgentPrivate()->setCacheSize(s); } void HostInfo::setTTL(int ttl) { hostInfoAgentPrivate()->setTTL(ttl); } HostInfoAgentPrivate::HostInfoAgentPrivate(int cacheSize) : openQueries(), dnsCache(cacheSize), ttl(TTL) { qRegisterMetaType(); } void HostInfoAgentPrivate::lookupHost(const QString &hostName, QObject *receiver, const char *member) { #ifdef _PATH_RESCONF QFileInfo resolvConf(QFile::decodeName(_PATH_RESCONF)); QDateTime currentMTime = resolvConf.lastModified(); if (resolvConf.exists() && currentMTime != resolvConfMTime) { // /etc/resolv.conf has been modified // clear our cache resolvConfMTime = currentMTime; dnsCache.clear(); } #endif if (QPair *info = dnsCache.object(hostName)) { if (QTime::currentTime() <= info->second.addSecs(ttl)) { Result result; if (receiver) { QObject::connect(&result, SIGNAL(result(QHostInfo)), receiver, member); emit result.result(info->first); } return; } dnsCache.remove(hostName); } if (Query *query = openQueries.value(hostName)) { if (receiver) { connect(query, SIGNAL(result(QHostInfo)), receiver, member); } return; } Query *query = new Query(); openQueries.insert(hostName, query); connect(query, SIGNAL(result(QHostInfo)), this, SLOT(queryFinished(QHostInfo))); if (receiver) { connect(query, SIGNAL(result(QHostInfo)), receiver, member); } query->start(hostName); } QHostInfo HostInfoAgentPrivate::lookupCachedHostInfoFor(const QString &hostName) { QPair *info = dnsCache.object(hostName); if (info && info->second.addSecs(ttl) >= QTime::currentTime()) { return info->first; } return QHostInfo(); } void HostInfoAgentPrivate::cacheLookup(const QHostInfo &info) { if (info.hostName().isEmpty()) { return; } if (info.error() != QHostInfo::NoError) { return; } dnsCache.insert(info.hostName(), new QPair(info, QTime::currentTime())); } void HostInfoAgentPrivate::queryFinished(const QHostInfo &info) { Query *query = static_cast(sender()); openQueries.remove(query->hostName()); if (info.error() == QHostInfo::NoError) { dnsCache.insert(query->hostName(), new QPair(info, QTime::currentTime())); } query->deleteLater(); } #include "hostinfo.moc" diff --git a/src/core/krecentdocument.cpp b/src/core/krecentdocument.cpp index 21a63048..90bd46f0 100644 --- a/src/core/krecentdocument.cpp +++ b/src/core/krecentdocument.cpp @@ -1,180 +1,181 @@ /* -*- c++ -*- * Copyright (C)2000 Daniel M. Duley * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include "krecentdocument.h" #ifdef Q_OS_WIN #include #else #include #endif #include #include #include #include #include #include #include #include #include QString KRecentDocument::recentDocumentDirectory() { // need to change this path, not sure where return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QLatin1String("RecentDocuments/"); } QStringList KRecentDocument::recentDocuments() { QDir d(recentDocumentDirectory(), QStringLiteral("*.desktop"), QDir::Time, QDir::Files | QDir::Readable | QDir::Hidden); if (!d.exists()) { d.mkdir(recentDocumentDirectory()); } const QStringList list = d.entryList(); QStringList fullList; for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { QString fileName = *it; QString pathDesktop; if (fileName.startsWith(QLatin1String(":"))) { // See: https://bugreports.qt.io/browse/QTBUG-11223 pathDesktop = KRecentDocument::recentDocumentDirectory() + *it; } else { pathDesktop = d.absoluteFilePath(*it); } KDesktopFile tmpDesktopFile(pathDesktop); QUrl urlDesktopFile(tmpDesktopFile.desktopGroup().readPathEntry("URL", QString())); if (urlDesktopFile.isLocalFile() && !QFile(urlDesktopFile.toLocalFile()).exists()) { d.remove(pathDesktop); } else { fullList.append(pathDesktop); } } return fullList; } void KRecentDocument::add(const QUrl &url) { // desktopFileName is in QGuiApplication but we're in KIO Core here QString desktopEntryName = QCoreApplication::instance()->property("desktopFileName").toString(); if (desktopEntryName.isEmpty()) { desktopEntryName = QCoreApplication::applicationName(); } KRecentDocument::add(url, desktopEntryName); // ### componentName might not match the service filename... } void KRecentDocument::add(const QUrl &url, const QString &desktopEntryName) { if (url.isLocalFile() && url.toLocalFile().startsWith(QDir::tempPath())) { return; // inside tmp resource, do not save } QString openStr = url.toDisplayString(); openStr.replace(QRegExp(QStringLiteral("\\$")), QStringLiteral("$$")); // Desktop files with type "Link" are $-variable expanded // qDebug() << "KRecentDocument::add for " << openStr; KConfigGroup config = KSharedConfig::openConfig()->group(QByteArray("RecentDocuments")); bool useRecent = config.readEntry(QStringLiteral("UseRecent"), true); int maxEntries = config.readEntry(QStringLiteral("MaxEntries"), 10); if (!useRecent || maxEntries <= 0) { return; } const QString path = recentDocumentDirectory(); const QString fileName = url.fileName(); // don't create a file called ".desktop", it will lead to an empty name in kio_recentdocuments const QString dStr = path + (fileName.isEmpty() ? QStringLiteral("unnamed") : fileName); QString ddesktop = dStr + QLatin1String(".desktop"); int i = 1; // check for duplicates while (QFile::exists(ddesktop)) { // see if it points to the same file and application KDesktopFile tmp(ddesktop); if (tmp.desktopGroup().readPathEntry("URL", QString()) == url.toDisplayString() && tmp.desktopGroup().readEntry("X-KDE-LastOpenedWith") == desktopEntryName) { // Set access and modification time to current time ::utime(QFile::encodeName(ddesktop).constData(), nullptr); return; } // if not append a (num) to it ++i; if (i > maxEntries) { break; } ddesktop = dStr + QStringLiteral("[%1].desktop").arg(i); } QDir dir(path); // check for max entries, delete oldest files if exceeded const QStringList list = dir.entryList(QDir::Files | QDir::Hidden, QFlags(QDir::Time | QDir::Reversed)); i = list.count(); if (i > maxEntries - 1) { QStringList::ConstIterator it; it = list.begin(); while (i > maxEntries - 1) { QFile::remove(dir.absolutePath() + QLatin1String("/") + (*it)); - --i, ++it; + --i; + ++it; } } // create the applnk KDesktopFile configFile(ddesktop); KConfigGroup conf = configFile.desktopGroup(); conf.writeEntry("Type", QStringLiteral("Link")); conf.writePathEntry("URL", openStr); // If you change the line below, change the test in the above loop conf.writeEntry("X-KDE-LastOpenedWith", desktopEntryName); conf.writeEntry("Name", url.fileName()); conf.writeEntry("Icon", KIO::iconNameForUrl(url)); } void KRecentDocument::clear() { const QStringList list = recentDocuments(); QDir dir; for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { dir.remove(*it); } } int KRecentDocument::maximumItems() { KConfigGroup cg(KSharedConfig::openConfig(), QStringLiteral("RecentDocuments")); return cg.readEntry(QStringLiteral("MaxEntries"), 10); } diff --git a/src/core/listjob.h b/src/core/listjob.h index 6f3b1dba..9a9864e9 100644 --- a/src/core/listjob.h +++ b/src/core/listjob.h @@ -1,142 +1,142 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2009 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_LISTJOB_H #define KIO_LISTJOB_H #include "simplejob.h" #include namespace KIO { class ListJobPrivate; /** * @class KIO::ListJob listjob.h * * A ListJob is allows you to get the get the content of a directory. * Don't create the job directly, but use KIO::listRecursive() or * KIO::listDir() instead. * @see KIO::listRecursive() * @see KIO::listDir() */ class KIOCORE_EXPORT ListJob : public SimpleJob { Q_OBJECT public: - ~ListJob(); + ~ListJob() Q_DECL_OVERRIDE; /** * Returns the ListJob's redirection URL. This will be invalid if there * was no redirection. * @return the redirection url */ const QUrl &redirectionUrl() const; /** * Do not apply any KIOSK restrictions to this job. */ void setUnrestricted(bool unrestricted); Q_SIGNALS: /** * This signal emits the entry found by the job while listing. * The progress signals aren't specific to ListJob. It simply * uses SimpleJob's processedSize (number of entries listed) and * totalSize (total number of entries, if known), * as well as percent. * @param job the job that emitted this signal * @param list the list of UDSEntries */ void entries(KIO::Job *job, const KIO::UDSEntryList &list); // TODO KDE5: use KIO::ListJob* argument to avoid casting /** * This signal is emitted when a sub-directory could not be listed. * The job keeps going, thus doesn't result in an overall error. * @param job the job that emitted the signal * @param subJob the job listing a sub-directory, which failed. Use * url(), error() and errorText() on that job to find * out more. */ void subError(KIO::ListJob *job, KIO::ListJob *subJob); /** * Signals a redirection. * Use to update the URL shown to the user. * The redirection itself is handled internally. * @param job the job that is redirected * @param url the new url */ void redirection(KIO::Job *job, const QUrl &url); /** * Signals a permanent redirection. * The redirection itself is handled internally. * @param job the job that emitted this signal * @param fromUrl the original URL * @param toUrl the new URL */ void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl); protected Q_SLOTS: void slotFinished() Q_DECL_OVERRIDE; void slotMetaData(const KIO::MetaData &_metaData) Q_DECL_OVERRIDE; void slotResult(KJob *job) Q_DECL_OVERRIDE; protected: ListJob(ListJobPrivate &dd); Q_DECLARE_PRIVATE(ListJob) }; /** * List the contents of @p url, which is assumed to be a directory. * * "." and ".." are returned, filter them out if you don't want them. * * * @param url the url of the directory * @param flags Can be HideProgressInfo here * @param includeHidden true for all files, false to cull out UNIX hidden * files/dirs (whose names start with dot) * @return the job handling the operation. */ KIOCORE_EXPORT ListJob *listDir(const QUrl &url, JobFlags flags = DefaultFlags, bool includeHidden = true); /** * The same as the previous method, but recurses subdirectories. * Directory links are not followed. * * "." and ".." are returned but only for the toplevel directory. * Filter them out if you don't want them. * * @param url the url of the directory * @param flags Can be HideProgressInfo here * @param includeHidden true for all files, false to cull out UNIX hidden * files/dirs (whose names start with dot) * @return the job handling the operation. */ KIOCORE_EXPORT ListJob *listRecursive(const QUrl &url, JobFlags flags = DefaultFlags, bool includeHidden = true); } #endif diff --git a/src/core/mimetypejob.h b/src/core/mimetypejob.h index d18e7090..a735ae34 100644 --- a/src/core/mimetypejob.h +++ b/src/core/mimetypejob.h @@ -1,70 +1,70 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2009 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_MIMETYPEJOB_H #define KIO_MIMETYPEJOB_H #include // filesize_t #include "transferjob.h" namespace KIO { class MimetypeJobPrivate; /** * @class KIO::MimetypeJob mimetypejob.h * * A MimetypeJob is a TransferJob that allows you to get * the mime type of an URL. Don't create directly, * but use KIO::mimetype() instead. * @see KIO::mimetype() */ class KIOCORE_EXPORT MimetypeJob : public TransferJob { Q_OBJECT public: - ~MimetypeJob(); + ~MimetypeJob() Q_DECL_OVERRIDE; protected Q_SLOTS: void slotFinished() Q_DECL_OVERRIDE; protected: MimetypeJob(MimetypeJobPrivate &dd); private: Q_DECLARE_PRIVATE(MimetypeJob) }; /** * Find mimetype for one file or directory. * * If you are going to download the file right after determining its mimetype, * then don't use this, prefer using a KIO::get() job instead. See the note * about putting the job on hold once the mimetype is determined. * * @param url the URL of the file * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT MimetypeJob *mimetype(const QUrl &url, JobFlags flags = DefaultFlags); } #endif diff --git a/src/core/mkdirjob.h b/src/core/mkdirjob.h index c0a65710..a4f09a6c 100644 --- a/src/core/mkdirjob.h +++ b/src/core/mkdirjob.h @@ -1,87 +1,87 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2009 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MKDIRJOB_H #define MKDIRJOB_H #include "kiocore_export.h" #include "simplejob.h" namespace KIO { class MkdirJobPrivate; /** * @class KIO::MkdirJob mkdirjob.h * * A KIO job that creates a directory * @see KIO::mkdir() */ class KIOCORE_EXPORT MkdirJob : public SimpleJob { Q_OBJECT public: - ~MkdirJob(); + ~MkdirJob() Q_DECL_OVERRIDE; Q_SIGNALS: /** * Signals a redirection. * Use to update the URL shown to the user. * The redirection itself is handled internally. * @param job the job that is redirected * @param url the new url */ void redirection(KIO::Job *job, const QUrl &url); /** * Signals a permanent redirection. * The redirection itself is handled internally. * @param job the job that is redirected * @param fromUrl the original URL * @param toUrl the new URL */ void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl); protected Q_SLOTS: void slotFinished() Q_DECL_OVERRIDE; public: MkdirJob(MkdirJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotRedirection(const QUrl &url)) Q_DECLARE_PRIVATE(MkdirJob) }; /** * Creates a single directory. * * @param url The URL of the directory to create. * @param permissions The permissions to set after creating the * directory (unix-style), -1 for default permissions. * @return A pointer to the job handling the operation. */ KIOCORE_EXPORT MkdirJob *mkdir(const QUrl &url, int permissions = -1); } #endif /* MKDIRJOB_H */ diff --git a/src/core/mkpathjob.cpp b/src/core/mkpathjob.cpp index cff2d2b2..c710694a 100644 --- a/src/core/mkpathjob.cpp +++ b/src/core/mkpathjob.cpp @@ -1,159 +1,159 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2009 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "mkpathjob.h" #include "job_p.h" #include "mkdirjob.h" #include "../pathhelpers_p.h" #include #include #include #include using namespace KIO; class KIO::MkpathJobPrivate : public KIO::JobPrivate { public: MkpathJobPrivate(const QUrl &url, const QUrl &baseUrl, JobFlags flags) : JobPrivate(), m_url(url), - m_pathComponents(url.path().split('/', QString::SkipEmptyParts)), + m_pathComponents(url.path().split(QLatin1Char('/'), QString::SkipEmptyParts)), m_pathIterator(), m_flags(flags) { const QStringList basePathComponents = baseUrl.path().split('/', QString::SkipEmptyParts); m_url.setPath(QStringLiteral("/")); int i = 0; for (; i < basePathComponents.count() && i < m_pathComponents.count(); ++i) { const QString pathComponent = m_pathComponents.at(i); if (pathComponent == basePathComponents.at(i)) { m_url.setPath(concatPaths(m_url.path(), pathComponent)); } else { break; } } if (i > 0) { m_pathComponents.erase(m_pathComponents.begin(), m_pathComponents.begin() + i); } // fast path for local files using QFileInfo::isDir if (m_url.isLocalFile()) { i = 0; for (; i < m_pathComponents.count(); ++i) { const QString localFile = m_url.toLocalFile(); QString testDir; if (localFile == QLatin1String("/")) { testDir = localFile + m_pathComponents.at(i); } else { testDir = localFile + '/' + m_pathComponents.at(i); } if (QFileInfo(testDir).isDir()) { m_url.setPath(testDir); } else { break; } } if (i > 0) { m_pathComponents.erase(m_pathComponents.begin(), m_pathComponents.begin() + i); } } m_pathIterator = m_pathComponents.constBegin(); } QUrl m_url; QUrl m_baseUrl; QStringList m_pathComponents; QStringList::const_iterator m_pathIterator; const JobFlags m_flags; Q_DECLARE_PUBLIC(MkpathJob) void slotStart(); static inline MkpathJob *newJob(const QUrl &url, const QUrl &baseUrl, JobFlags flags) { MkpathJob *job = new MkpathJob(*new MkpathJobPrivate(url, baseUrl, flags)); job->setUiDelegate(KIO::createDefaultJobUiDelegate()); if (!(flags & HideProgressInfo)) { KIO::getJobTracker()->registerJob(job); } if (!(flags & NoPrivilegeExecution)) { job->d_func()->m_privilegeExecutionEnabled = true; job->d_func()->m_operationType = MkDir; } return job; } }; MkpathJob::MkpathJob(MkpathJobPrivate &dd) : Job(dd) { QTimer::singleShot(0, this, SLOT(slotStart())); } MkpathJob::~MkpathJob() { } void MkpathJobPrivate::slotStart() { Q_Q(MkpathJob); if (m_pathIterator == m_pathComponents.constBegin()) { // first time: emit total q->setTotalAmount(KJob::Directories, m_pathComponents.count()); } if (m_pathIterator != m_pathComponents.constEnd()) { m_url.setPath(concatPaths(m_url.path(), *m_pathIterator)); KIO::Job* job = KIO::mkdir(m_url); job->setParentJob(q); q->addSubjob(job); q->setProcessedAmount(KJob::Directories, q->processedAmount(KJob::Directories) + 1); } else { q->emitResult(); } } void MkpathJob::slotResult(KJob *job) { Q_D(MkpathJob); if (job->error() && job->error() != KIO::ERR_DIR_ALREADY_EXIST) { KIO::Job::slotResult(job); // will set the error and emit result(this) return; } removeSubjob(job); emit directoryCreated(d->m_url); // Move on to next one ++d->m_pathIterator; emitPercent(d->m_pathIterator - d->m_pathComponents.constBegin(), d->m_pathComponents.count()); d->slotStart(); } MkpathJob * KIO::mkpath(const QUrl &url, const QUrl &baseUrl, KIO::JobFlags flags) { return MkpathJobPrivate::newJob(url, baseUrl, flags); } #include "moc_mkpathjob.cpp" diff --git a/src/core/mkpathjob.h b/src/core/mkpathjob.h index 6244c677..ef084f71 100644 --- a/src/core/mkpathjob.h +++ b/src/core/mkpathjob.h @@ -1,84 +1,84 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2014 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MKPATHJOB_H #define MKPATHJOB_H #include #include "kiocore_export.h" #include "job_base.h" namespace KIO { class MkpathJobPrivate; /** * @class KIO::MkpathJob mkpathjob.h * * A KIO job that creates a directory, after creating all parent * directories necessary for this. * * @see KIO::mkpath(), KIO::mkdir() * @since 5.4 */ class KIOCORE_EXPORT MkpathJob : public Job { Q_OBJECT public: - virtual ~MkpathJob(); + ~MkpathJob() Q_DECL_OVERRIDE; Q_SIGNALS: /** * Signals that a directory was created. */ void directoryCreated(const QUrl &url); protected Q_SLOTS: void slotResult(KJob *job) Q_DECL_OVERRIDE; protected: MkpathJob(MkpathJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotStart()) Q_DECLARE_PRIVATE(MkpathJob) }; /** * Creates a directory, creating parent directories as needed. * Unlike KIO::mkdir(), the job will succeed if the directory exists already. * * @param url The URL of the directory to create. * @param baseUrl Optionally, the URL to start from, which is known to exist * (e.g. the directory currently listed). * @param flags mkpath() supports HideProgressInfo. * * If @p baseUrl is not an ancestor of @p url, @p baseUrl will be ignored. * * @return A pointer to the job handling the operation. * @since 5.4 */ KIOCORE_EXPORT MkpathJob *mkpath(const QUrl &url, const QUrl &baseUrl = QUrl(), JobFlags flags = DefaultFlags); } #endif /* MKPATHJOB_H */ diff --git a/src/core/multigetjob.h b/src/core/multigetjob.h index 2bdadde0..52020d3a 100644 --- a/src/core/multigetjob.h +++ b/src/core/multigetjob.h @@ -1,105 +1,105 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2009 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MULTIGETJOB_H #define MULTIGETJOB_H #include "transferjob.h" namespace KIO { class MultiGetJobPrivate; /** * @class KIO::MultiGetJob multigetjob.h * * The MultiGetJob is a TransferJob that allows you to get * several files from a single server. Don't create directly, * but use KIO::multi_get() instead. * @see KIO::multi_get() */ class KIOCORE_EXPORT MultiGetJob : public TransferJob { Q_OBJECT public: - virtual ~MultiGetJob(); + ~MultiGetJob() Q_DECL_OVERRIDE; /** * Get an additional file. * * @param id the id of the file * @param url the url of the file to get * @param metaData the meta data for this request */ void get(long id, const QUrl &url, const MetaData &metaData); Q_SIGNALS: /** * Data from the slave has arrived. * @param id the id of the request * @param data data received from the slave. * End of data (EOD) has been reached if data.size() == 0 */ void data(long id, const QByteArray &data); /** * Mimetype determined * @param id the id of the request * @param type the mime type */ void mimetype(long id, const QString &type); /** * File transfer completed. * * When all files have been processed, result(KJob *) gets * emitted. * @param id the id of the request */ void result(long id); protected Q_SLOTS: void slotRedirection(const QUrl &url) Q_DECL_OVERRIDE; void slotFinished() Q_DECL_OVERRIDE; void slotData(const QByteArray &data) Q_DECL_OVERRIDE; void slotMimetype(const QString &mimetype) Q_DECL_OVERRIDE; protected: MultiGetJob(MultiGetJobPrivate &dd); private: Q_DECLARE_PRIVATE(MultiGetJob) }; /** * Creates a new multiple get job. * * @param id the id of the get operation * @param url the URL of the file * @param metaData the MetaData associated with the file * * @return the job handling the operation. * @see get() */ KIOCORE_EXPORT MultiGetJob *multi_get(long id, const QUrl &url, const MetaData &metaData); } #endif diff --git a/src/core/restorejob.h b/src/core/restorejob.h index a2b8cf78..a6c5980a 100644 --- a/src/core/restorejob.h +++ b/src/core/restorejob.h @@ -1,85 +1,85 @@ /* This file is part of the KDE libraries Copyright 2014 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_RESTOREJOB_H #define KIO_RESTOREJOB_H #include #include #include "kiocore_export.h" #include "job_base.h" namespace KIO { class RestoreJobPrivate; /** * @class KIO::RestoreJob restorejob.h * * RestoreJob is used to restore files from the trash. * Don't create the job directly, but use KIO::restoreFromTrash(). * * @see KIO::trash() * @see KIO::copy() * @since 5.2 */ class KIOCORE_EXPORT RestoreJob : public Job { Q_OBJECT public: - virtual ~RestoreJob(); + ~RestoreJob() Q_DECL_OVERRIDE; /** * Returns the list of trash URLs to restore. */ QList trashUrls() const; Q_SIGNALS: protected Q_SLOTS: void slotResult(KJob *job) Q_DECL_OVERRIDE; protected: RestoreJob(RestoreJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotStart()) Q_DECLARE_PRIVATE(RestoreJob) }; /** * Restore a set of trashed files or directories. * @since 5.2 * * @param urls the trash:/ URLs to restore. The trash implementation * will know where the files came from and will restore them to their * original location. * * @param flags restoreFromTrash() supports HideProgressInfo. * * @return the job handling the operation */ KIOCORE_EXPORT RestoreJob *restoreFromTrash(const QList &urls, JobFlags flags = DefaultFlags); } #endif diff --git a/src/core/simplejob.h b/src/core/simplejob.h index c11a3efd..010ac346 100644 --- a/src/core/simplejob.h +++ b/src/core/simplejob.h @@ -1,276 +1,276 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2013 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_SIMPLEJOB_H #define KIO_SIMPLEJOB_H #include "job_base.h" #include // filesize_t namespace KIO { class SimpleJobPrivate; /** * @class KIO::SimpleJob simplejob.h * * A simple job (one url and one command). * This is the base class for all jobs that are scheduled. * Other jobs are high-level jobs (CopyJob, DeleteJob, FileCopyJob...) * that manage subjobs but aren't scheduled directly. */ class KIOCORE_EXPORT SimpleJob : public KIO::Job { Q_OBJECT public: - ~SimpleJob(); + ~SimpleJob() Q_DECL_OVERRIDE; protected: /** * Suspend this job * @see resume */ bool doSuspend() Q_DECL_OVERRIDE; /** * Resume this job * @see suspend */ bool doResume() Q_DECL_OVERRIDE; /** * Abort job. * This kills all subjobs and deletes the job. */ bool doKill() Q_DECL_OVERRIDE; public: /** * Returns the SimpleJob's URL * @return the url */ const QUrl &url() const; /** * Abort job. * Suspends slave to be reused by another job for the same request. */ virtual void putOnHold(); /** * Discard suspended slave. */ static void removeOnHold(); /** * Returns true when redirections are handled internally, the default. * * @since 4.4 */ bool isRedirectionHandlingEnabled() const; /** * Set @p handle to false to prevent the internal handling of redirections. * * When this flag is set, redirection requests are simply forwarded to the * caller instead of being handled internally. * * @since 4.4 */ void setRedirectionHandlingEnabled(bool handle); public Q_SLOTS: /** * @internal * Called on a slave's error. * Made public for the scheduler. */ void slotError(int, const QString &); protected Q_SLOTS: /** * Called when the slave marks the job * as finished. */ virtual void slotFinished(); /** * @internal * Called on a slave's warning. */ virtual void slotWarning(const QString &); /** * MetaData from the slave is received. * @param _metaData the meta data * @see metaData() */ virtual void slotMetaData(const KIO::MetaData &_metaData); protected: /** * Allow jobs that inherit SimpleJob and are aware * of redirections to store the SSL session used. * Retrieval is handled by SimpleJob::start * @param m_redirectionURL Reference to redirection URL, * used instead of m_url if not empty */ void storeSSLSessionFromJob(const QUrl &m_redirectionURL); /** * Creates a new simple job. You don't need to use this constructor, * unless you create a new job that inherits from SimpleJob. */ SimpleJob(SimpleJobPrivate &dd); private: Q_DECLARE_PRIVATE(SimpleJob) }; /** * Removes a single directory. * * The directory is assumed to be empty. * The job will fail if the directory is not empty. * Use KIO::del() (DeleteJob) to delete non-empty directories. * * @param url The URL of the directory to remove. * @return A pointer to the job handling the operation. */ KIOCORE_EXPORT SimpleJob *rmdir(const QUrl &url); /** * Changes permissions on a file or directory. * See the other chmod in chmodjob.h for changing many files * or directories. * * @param url The URL of file or directory. * @param permissions The permissions to set. * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *chmod(const QUrl &url, int permissions); /** * Changes ownership and group of a file or directory. * * @param url The URL of file or directory. * @param owner the new owner * @param group the new group * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *chown(const QUrl &url, const QString &owner, const QString &group); /** * Changes the modification time on a file or directory. * * @param url The URL of file or directory. * @param mtime The modification time to set. * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *setModificationTime(const QUrl &url, const QDateTime &mtime); /** * Rename a file or directory. * Warning: this operation fails if a direct renaming is not * possible (like with files or dirs on separate partitions) * Use move or file_move in this case. * * @param src The original URL * @param dest The final URL * @param flags Can be Overwrite here * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *rename(const QUrl &src, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Create or move a symlink. * This is the lowlevel operation, similar to file_copy and file_move. * It doesn't do any check (other than those the slave does) * and it doesn't show rename and skip dialogs - use KIO::link for that. * @param target The string that will become the "target" of the link (can be relative) * @param dest The symlink to create. * @param flags Can be Overwrite and HideProgressInfo * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *symlink(const QString &target, const QUrl &dest, JobFlags flags = DefaultFlags); /** * Execute any command that is specific to one slave (protocol). * * Examples are : HTTP POST, mount and unmount (kio_file) * * @param url The URL isn't passed to the slave, but is used to know * which slave to send it to :-) * @param data Packed data. The meaning is completely dependent on the * slave, but usually starts with an int for the command number. * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *special(const QUrl &url, const QByteArray &data, JobFlags flags = DefaultFlags); /** * Mount filesystem. * * Special job for @p kio_file. * * @param ro Mount read-only if @p true. * @param fstype File system type (e.g. "ext2", can be empty). * @param dev Device (e.g. /dev/sda0). * @param point Mount point, can be @p null. * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *mount(bool ro, const QByteArray &fstype, const QString &dev, const QString &point, JobFlags flags = DefaultFlags); /** * Unmount filesystem. * * Special job for @p kio_file. * * @param point Point to unmount. * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *unmount(const QString &point, JobFlags flags = DefaultFlags); /** * HTTP cache update * * @param url Url to update, protocol must be "http". * @param no_cache If true, cache entry for @p url is deleted. * @param expireDate Local machine time indicating when the entry is * supposed to expire. * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *http_update_cache(const QUrl &url, bool no_cache, const QDateTime &expireDate); /** * Delete a single file. * * @param src File to delete. * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT SimpleJob *file_delete(const QUrl &src, JobFlags flags = DefaultFlags); } #endif diff --git a/src/core/statjob.h b/src/core/statjob.h index 6865f2db..4c7fdab7 100644 --- a/src/core/statjob.h +++ b/src/core/statjob.h @@ -1,230 +1,230 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2013 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_STATJOB_H #define KIO_STATJOB_H #include "simplejob.h" #include namespace KIO { class StatJobPrivate; /** * @class KIO::StatJob statjob.h * * A KIO job that retrieves information about a file or directory. * @see KIO::stat() */ class KIOCORE_EXPORT StatJob : public SimpleJob { Q_OBJECT public: enum StatSide { SourceSide, DestinationSide }; - ~StatJob(); + ~StatJob() Q_DECL_OVERRIDE; /** * A stat() can have two meanings. Either we want to read from this URL, * or to check if we can write to it. First case is "source", second is "dest". * It is necessary to know what the StatJob is for, to tune the kioslave's behavior * (e.g. with FTP). * By default it is SourceSide. * @param side SourceSide or DestinationSide */ void setSide(StatSide side); /** * A stat() can have two meanings. Either we want to read from this URL, * or to check if we can write to it. First case is "source", second is "dest". * It is necessary to know what the StatJob is for, to tune the kioslave's behavior * (e.g. with FTP). * @param source true for "source" mode, false for "dest" mode * @deprecated use setSide(StatSide side). */ #ifndef KIOCORE_NO_DEPRECATED KIOCORE_DEPRECATED void setSide(bool source); #endif /** * Selects the level of @p details we want. * By default this is 2 (all details wanted, including modification time, size, etc.), * setDetails(1) is used when deleting: we don't need all the information if it takes * too much time, no need to follow symlinks etc. * setDetails(0) is used for very simple probing: we'll only get the answer * "it's a file or a directory, or it doesn't exist". This is used by KRun. * @param details 2 for all details, 1 for simple, 0 for very simple */ void setDetails(short int details); /** * @brief Result of the stat operation. * Call this in the slot connected to result, * and only after making sure no error happened. * @return the result of the stat */ const UDSEntry &statResult() const; /** * @brief most local URL * Call this in the slot connected to result, * and only after making sure no error happened. * @return the most local URL for the URL we were stat'ing. * * Sample usage: * * @code * KIO::StatJob* job = KIO::mostLocalUrl("desktop:/foo"); * job->uiDelegate()->setWindow(this); * connect(job, SIGNAL(result(KJob*)), this, SLOT(slotMostLocalUrlResult(KJob*))); * [...] * // and in the slot * if (job->error()) { * [...] // doesn't exist * } else { * const QUrl localUrl = job->mostLocalUrl(); * // localUrl = file:///$HOME/Desktop/foo * [...] * } * @endcode * * \since 4.4 */ QUrl mostLocalUrl() const; Q_SIGNALS: /** * Signals a redirection. * Use to update the URL shown to the user. * The redirection itself is handled internally. * @param job the job that is redirected * @param url the new url */ void redirection(KIO::Job *job, const QUrl &url); /** * Signals a permanent redirection. * The redirection itself is handled internally. * @param job the job that is redirected * @param fromUrl the original URL * @param toUrl the new URL */ void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl); protected Q_SLOTS: void slotFinished() Q_DECL_OVERRIDE; void slotMetaData(const KIO::MetaData &_metaData) Q_DECL_OVERRIDE; protected: StatJob(StatJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotStatEntry(const KIO::UDSEntry &entry)) Q_PRIVATE_SLOT(d_func(), void slotRedirection(const QUrl &url)) Q_DECLARE_PRIVATE(StatJob) }; /** * Find all details for one file or directory. * * @param url the URL of the file * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT StatJob *stat(const QUrl &url, JobFlags flags = DefaultFlags); /** * Find all details for one file or directory. * This version of the call includes two additional booleans, @p sideIsSource and @p details. * * @param url the URL of the file * @param side is SourceSide when stating a source file (we will do a get on it if * the stat works) and DestinationSide when stating a destination file (target of a copy). * The reason for this parameter is that in some cases the kioslave might not * be able to determine a file's existence (e.g. HTTP doesn't allow it, FTP * has issues with case-sensitivity on some systems). * When the slave can't reliably determine the existence of a file, it will: * @li be optimistic if SourceSide, i.e. it will assume the file exists, * and if it doesn't this will appear when actually trying to download it * @li be pessimistic if DestinationSide, i.e. it will assume the file * doesn't exist, to prevent showing "about to overwrite" errors to the user. * If you simply want to check for existence without downloading/uploading afterwards, * then you should use DestinationSide. * * @param details selects the level of details we want. * By default this is 2 (all details wanted, including modification time, size, etc.), * setDetails(1) is used when deleting: we don't need all the information if it takes * too much time, no need to follow symlinks etc. * setDetails(0) is used for very simple probing: we'll only get the answer * "it's a file or a directory or a symlink, or it doesn't exist". This is used by KRun and DeleteJob. * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT StatJob *stat(const QUrl &url, KIO::StatJob::StatSide side, short int details, JobFlags flags = DefaultFlags); /** * Find all details for one file or directory. * This version of the call includes two additional booleans, @p sideIsSource and @p details. * * @param url the URL of the file * @param sideIsSource is true when stating a source file (we will do a get on it if * the stat works) and false when stating a destination file (target of a copy). * The reason for this parameter is that in some cases the kioslave might not * be able to determine a file's existence (e.g. HTTP doesn't allow it, FTP * has issues with case-sensitivity on some systems). * When the slave can't reliably determine the existence of a file, it will: * @li be optimistic if sideIsSource=true, i.e. it will assume the file exists, * and if it doesn't this will appear when actually trying to download it * @li be pessimistic if sideIsSource=false, i.e. it will assume the file * doesn't exist, to prevent showing "about to overwrite" errors to the user. * If you simply want to check for existence without downloading/uploading afterwards, * then you should use sideIsSource=false. * * @param details selects the level of details we want. * By default this is 2 (all details wanted, including modification time, size, etc.), * setDetails(1) is used when deleting: we don't need all the information if it takes * too much time, no need to follow symlinks etc. * setDetails(0) is used for very simple probing: we'll only get the answer * "it's a file or a directory, or it doesn't exist". This is used by KRun. * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ #ifndef KIOCORE_NO_DEPRECATED KIOCORE_DEPRECATED_EXPORT StatJob *stat(const QUrl &url, bool sideIsSource, short int details, JobFlags flags = DefaultFlags); #endif /** * Tries to map a local URL for the given URL, using a KIO job. * * Starts a (stat) job for determining the "most local URL" for a given URL. * Retrieve the result with StatJob::mostLocalUrl in the result slot. * @param url The URL we are testing. * \since 4.4 */ KIOCORE_EXPORT StatJob *mostLocalUrl(const QUrl &url, JobFlags flags = DefaultFlags); } #endif diff --git a/src/core/tcpslavebase.h b/src/core/tcpslavebase.h index 71c69fcf..2ebc7484 100644 --- a/src/core/tcpslavebase.h +++ b/src/core/tcpslavebase.h @@ -1,230 +1,230 @@ /* * Copyright (C) 2000 Alex Zepeda * Copyright (C) 2001 George Staikos * Copyright (C) 2001 Dawit Alemayehu * Copyright (C) 2007,2008 Andreas Hartmetz * * This file is part of the KDE project * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef _TCP_SLAVEBASE_H #define _TCP_SLAVEBASE_H #include #include #include "kiocore_export.h" #include class QIODevice; namespace KIO { /** * @class KIO::TCPSlaveBase tcpslavebase.h * * There are two classes that specifies the protocol between application (job) * and kioslave. SlaveInterface is the class to use on the application end, * SlaveBase is the one to use on the slave end. * * Slave implementations should simply inherit SlaveBase * * A call to foo() results in a call to slotFoo() on the other end. */ class KIOCORE_EXPORT TCPSlaveBase : public SlaveBase { public: /** * Constructor. * * @param autoSsl if true, will automatically invoke startSsl() right after * connecting. In the absence of errors the use of SSL will * therefore be transparent to higher layers. */ TCPSlaveBase(const QByteArray &protocol, const QByteArray &poolSocket, const QByteArray &appSocket, bool autoSsl = false); - virtual ~TCPSlaveBase(); + ~TCPSlaveBase() Q_DECL_OVERRIDE; protected: enum SslResultDetail { ResultOk = 1, ResultOverridden = 2, ResultFailed = 4, ResultFailedEarly = 8 }; friend class QFlags; public: Q_DECLARE_FLAGS(SslResult, SslResultDetail) protected: /** * Send data to the remote host. * * @param data data to be sent to remote machine * @param len the length (in bytes) of the data to be sent * * @return the actual size of the data that was sent */ using SlaveBase::write; //Silence incompatible virtual override warning ssize_t write(const char *data, ssize_t len); /** * Read incoming data from the remote host. * * @param data storage for the data read from server * @param len length of the data (in bytes) to read from the server * * @return the actual size of data that was obtained */ using SlaveBase::read; ssize_t read(char *data, ssize_t len); /** * Same as read() except it reads data one line at a time. */ ssize_t readLine(char *data, ssize_t len); /** * Performs the initial TCP connection stuff and/or * SSL handshaking as necessary. * * @param protocol the protocol being used * @param host hostname * @param port port number * * @return on succes, true is returned. * on failure, false is returned and an appropriate * error message is sent to the application. */ bool connectToHost(const QString &protocol, const QString &host, quint16 port); /** * Connects to the specified host and port. * * @param host host name * @param port port number * @param errorString if not NULL, this string will contain error information * on why the connection request failed. * * @return on success, 0 is returned. on failure, a KIO::Error code is returned. * @ref errorString, if not NULL, will contain the appropriate error message * that can be sent back to the client. * * @since 4.7.2 */ int connectToHost(const QString &host, quint16 port, QString *errorString = nullptr); /** * the current port for this service * */ quint16 port() const; /** * Will start SSL after connecting? * * @return if so, true is returned. * if not, false is returned. */ bool isAutoSsl() const; /** * Is the current connection using SSL? * * @return if so, true is returned. * if not, false is returned. */ bool isUsingSsl() const; /** * Start using SSL on the connection. You can use it right after connecting * for classic, transparent to the protocol SSL. Calling it later can be * used to implement e.g. SMTP's STARTTLS feature. * * @return on success, true is returned. * on failure, false is returned. */ bool startSsl(); /** * Close the connection and forget non-permanent data like the peer host. */ void disconnectFromHost(); /** * Returns true when end of data is reached. */ bool atEnd() const; /** * Determines whether or not we are still connected * to the remote machine. * * return @p true if the socket is still active or * false otherwise. */ bool isConnected() const; /** * Wait for incoming data on the socket * for the period specified by @p t. * * @param t length of time in seconds that we should monitor the * socket before timing out. * * @return true if any data arrived on the socket before the * timeout value was reached, false otherwise. */ bool waitForResponse(int t); /** * Sets the mode of the connection to blocking or non-blocking. * * Be sure to call this function before calling connectToHost. * Otherwise, this setting will not have any effect until the next * @p connectToHost. * * @param b true to make the connection a blocking one, false otherwise. */ void setBlocking(bool b); /** * Return the socket object, if the class ever needs to do anything to it */ QIODevice *socket() const; protected: void virtual_hook(int id, void *data) Q_DECL_OVERRIDE; private: // For the certificate verification code SslResult verifyServerCertificate(); // For prompting for the client certificate to use void selectClientCertificate(); class TcpSlaveBasePrivate; TcpSlaveBasePrivate *const d; }; } #endif diff --git a/src/core/transferjob.h b/src/core/transferjob.h index 612e14a7..0505e1e3 100644 --- a/src/core/transferjob.h +++ b/src/core/transferjob.h @@ -1,322 +1,322 @@ /* This file is part of the KDE libraries Copyright (C) 2000 Stephan Kulow 2000-2013 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIO_TRANSFERJOB_H #define KIO_TRANSFERJOB_H #include "simplejob.h" namespace KIO { class TransferJobPrivate; /** * @class KIO::TransferJob transferjob.h * * The transfer job pumps data into and/or out of a Slave. * Data is sent to the slave on request of the slave ( dataReq). * If data coming from the slave can not be handled, the * reading of data from the slave should be suspended. */ class KIOCORE_EXPORT TransferJob : public SimpleJob { Q_OBJECT public: - ~TransferJob(); + ~TransferJob() Q_DECL_OVERRIDE; /** * Sets the modification time of the file to be created (by KIO::put) * Note that some kioslaves might ignore this. */ void setModificationTime(const QDateTime &mtime); /** * Checks whether we got an error page. This currently only happens * with HTTP urls. Call this from your slot connected to result(). * * @return true if we got an (HTML) error page from the server * instead of what we asked for. */ bool isErrorPage() const; /** * Enable the async data mode. * When async data is enabled, data should be provided to the job by * calling sendAsyncData() instead of returning data in the * dataReq() signal. */ void setAsyncDataEnabled(bool enabled); /** * Provide data to the job when async data is enabled. * Should be called exactly once after receiving a dataReq signal * Sending an empty block indicates end of data. */ void sendAsyncData(const QByteArray &data); /** * When enabled, the job reports the amount of data that has been sent, * instead of the amount of data that has been received. * @see slotProcessedSize * @see slotSpeed * @deprecated since 4.2.1, this is unnecessary (it is always false for * KIO::get and true for KIO::put) */ #ifndef KIOCORE_NO_DEPRECATED KIOCORE_DEPRECATED void setReportDataSent(bool enabled); #endif /** * Returns whether the job reports the amount of data that has been * sent (true), or whether the job reports the amount of data that * has been received (false) * @deprecated since 4.2.1, this is unnecessary (it is always false for * KIO::get and true for KIO::put) */ #ifndef KIOCORE_NO_DEPRECATED KIOCORE_DEPRECATED bool reportDataSent() const; #endif /** * Call this in the slot connected to result, * and only after making sure no error happened. * @return the mimetype of the URL */ QString mimetype() const; /** * After the job has finished, it will return the final url in case a redirection * has happened. * @return the final url that can be empty in case no redirection has happened. * @since 5.0 */ QUrl redirectUrl() const; /** * Set the total size of data that we are going to send * in a put job. Helps getting proper progress information. * @since 4.2.1 */ void setTotalSize(KIO::filesize_t bytes); protected: /** * Called when m_subJob finishes. * @param job the job that finished */ void slotResult(KJob *job) Q_DECL_OVERRIDE; /** * Reimplemented for internal reasons */ bool doResume() Q_DECL_OVERRIDE; Q_SIGNALS: /** * Data from the slave has arrived. * @param job the job that emitted this signal * @param data data received from the slave. * * End of data (EOD) has been reached if data.size() == 0, however, you * should not be certain of data.size() == 0 ever happening (e.g. in case * of an error), so you should rely on result() instead. */ void data(KIO::Job *job, const QByteArray &data); /** * Request for data. * Please note, that you shouldn't put too large chunks * of data in it as this requires copies within the frame * work, so you should rather split the data you want * to pass here in reasonable chunks (about 1MB maximum) * * @param job the job that emitted this signal * @param data buffer to fill with data to send to the * slave. An empty buffer indicates end of data. (EOD) */ void dataReq(KIO::Job *job, QByteArray &data); /** * Signals a redirection. * Use to update the URL shown to the user. * The redirection itself is handled internally. * @param job the job that emitted this signal * @param url the new URL */ void redirection(KIO::Job *job, const QUrl &url); /** * Signals a permanent redirection. * The redirection itself is handled internally. * @param job the job that emitted this signal * @param fromUrl the original URL * @param toUrl the new URL */ void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl); /** * Mimetype determined. * @param job the job that emitted this signal * @param type the mime type */ void mimetype(KIO::Job *job, const QString &type); /** * @internal * Emitted if the "put" job found an existing partial file * (in which case offset is the size of that file) * and emitted by the "get" job if it supports resuming to * the given offset - in this case @p offset is unused) */ void canResume(KIO::Job *job, KIO::filesize_t offset); protected Q_SLOTS: virtual void slotRedirection(const QUrl &url); void slotFinished() Q_DECL_OVERRIDE; virtual void slotData(const QByteArray &data); virtual void slotDataReq(); virtual void slotMimetype(const QString &mimetype); void slotMetaData(const KIO::MetaData &_metaData) Q_DECL_OVERRIDE; protected: TransferJob(TransferJobPrivate &dd); private: Q_PRIVATE_SLOT(d_func(), void slotErrorPage()) Q_PRIVATE_SLOT(d_func(), void slotCanResume(KIO::filesize_t offset)) Q_PRIVATE_SLOT(d_func(), void slotPostRedirection()) Q_PRIVATE_SLOT(d_func(), void slotNeedSubUrlData()) Q_PRIVATE_SLOT(d_func(), void slotSubUrlData(KIO::Job *, const QByteArray &)) Q_PRIVATE_SLOT(d_func(), void slotDataReqFromDevice()) Q_PRIVATE_SLOT(d_func(), void slotIODeviceClosed()) Q_PRIVATE_SLOT(d_func(), void slotIODeviceClosedBeforeStart()) Q_DECLARE_PRIVATE(TransferJob) // A FileCopyJob may control one or more TransferJobs friend class FileCopyJob; friend class FileCopyJobPrivate; }; /** * Get (means: read). * This is the job to use in order to "download" a file into memory. * The slave emits the data through the data() signal. * * Special case: if you want to determine the mimetype of the file first, * and then read it with the appropriate component, you can still use * a KIO::get() directly. When that job emits the mimeType signal, (which is * guaranteed to happen before it emits any data), put the job on hold: * * @code * job->putOnHold(); * KIO::Scheduler::publishSlaveOnHold(); * @endcode * * and forget about the job. The next time someone does a KIO::get() on the * same URL (even in another process) this job will be resumed. This saves KIO * from doing two requests to the server. * * @param url the URL of the file * @param reload Reload to reload the file, NoReload if it can be taken from the cache * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT TransferJob *get(const QUrl &url, LoadType reload = NoReload, JobFlags flags = DefaultFlags); /** * Put (means: write) * * @param url Where to write data. * @param permissions May be -1. In this case no special permission mode is set. * @param flags Can be HideProgressInfo, Overwrite and Resume here. WARNING: * Setting Resume means that the data will be appended to @p dest if @p dest exists. * @return the job handling the operation. * @see multi_get() */ KIOCORE_EXPORT TransferJob *put(const QUrl &url, int permissions, JobFlags flags = DefaultFlags); /** * HTTP POST (for form data). * * Example: * \code * job = KIO::http_post( url, postData, KIO::HideProgressInfo ); * job->addMetaData("content-type", contentType ); * job->addMetaData("referrer", referrerURL); * \endcode * * @p postData is the data that you want to send and * @p contentType is the complete HTTP header line that * specifies the content's MIME type, for example * "Content-Type: text/xml". * * You MUST specify content-type! * * Often @p contentType is * "Content-Type: application/x-www-form-urlencoded" and * the @p postData is then an ASCII string (without null-termination!) * with characters like space, linefeed and percent escaped like %20, * %0A and %25. * * @param url Where to write the data. * @param postData Encoded data to post. * @param flags Can be HideProgressInfo here * @return the job handling the operation. */ KIOCORE_EXPORT TransferJob *http_post(const QUrl &url, const QByteArray &postData, JobFlags flags = DefaultFlags); /** * HTTP POST. * * This function, unlike the one that accepts a QByteArray, accepts an IO device * from which to read the encoded data to be posted to the server in order to * to avoid holding the content of very large post requests, e.g. multimedia file * uploads, in memory. * * @param url Where to write the data. * @param device the device to read from * @param size Size of the encoded post data. * @param flags Can be HideProgressInfo here * @return the job handling the operation. * * @since 4.7 */ KIOCORE_EXPORT TransferJob *http_post(const QUrl &url, QIODevice *device, qint64 size = -1, JobFlags flags = DefaultFlags); /** * HTTP DELETE. * * Though this function servers the same purpose as KIO::file_delete, unlike * file_delete it accommodates HTTP sepecific actions such as redirections. * * @param url url resource to delete. * @param flags Can be HideProgressInfo here * @return the job handling the operation. * * @since 4.7.3 */ KIOCORE_EXPORT TransferJob *http_delete(const QUrl &url, JobFlags flags = DefaultFlags); } #endif diff --git a/src/filewidgets/kdirsortfilterproxymodel.h b/src/filewidgets/kdirsortfilterproxymodel.h index b2418edd..8dfb8dc0 100644 --- a/src/filewidgets/kdirsortfilterproxymodel.h +++ b/src/filewidgets/kdirsortfilterproxymodel.h @@ -1,104 +1,104 @@ /* Copyright (C) 2006 by Peter Penz Copyright (C) 2006 by Dominic Battre Copyright (C) 2006 by Martin Pool Separated from Dolphin by Nick Shaforostoff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDIRSORTFILTERPROXYMODEL_H #define KDIRSORTFILTERPROXYMODEL_H #include #include #include "kiofilewidgets_export.h" /** * @class KDirSortFilterProxyModel kdirsortfilterproxymodel.h * * @brief Acts as proxy model for KDirModel to sort and filter * KFileItems. * * A natural sorting is done. This means that items like: * - item_10.png * - item_1.png * - item_2.png * * are sorted like * - item_1.png * - item_2.png * - item_10.png * * Don't use it with non-KDirModel derivatives. * * @author Dominic Battre, Martin Pool and Peter Penz */ class KIOFILEWIDGETS_EXPORT KDirSortFilterProxyModel : public KCategorizedSortFilterProxyModel { Q_OBJECT public: - KDirSortFilterProxyModel(QObject *parent = nullptr); - virtual ~KDirSortFilterProxyModel(); + explicit KDirSortFilterProxyModel(QObject *parent = nullptr); + ~KDirSortFilterProxyModel() Q_DECL_OVERRIDE; /** Reimplemented from QAbstractItemModel. Returns true for directories. */ bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /** * Reimplemented from QAbstractItemModel. * Returns true for 'empty' directories so they can be populated later. */ bool canFetchMore(const QModelIndex &parent) const Q_DECL_OVERRIDE; /** * Returns the permissions in "points". This is useful for sorting by * permissions. */ static int pointsForPermissions(const QFileInfo &info); /** * Choose if files and folders are sorted separately (with folders first) or not. * @since 4.3 */ void setSortFoldersFirst(bool foldersFirst); /** * Returns if files and folders are sorted separately (with folders first) or not. * @since 4.3 */ bool sortFoldersFirst() const; Qt::DropActions supportedDragOptions() const; protected: /** * Reimplemented from KCategorizedSortFilterProxyModel. */ virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; private: Q_PRIVATE_SLOT(d, void slotNaturalSortingChanged()) private: class KDirSortFilterProxyModelPrivate; KDirSortFilterProxyModelPrivate *const d; }; #endif diff --git a/src/filewidgets/kfilebookmarkhandler_p.h b/src/filewidgets/kfilebookmarkhandler_p.h index 463c0f67..f970eae5 100644 --- a/src/filewidgets/kfilebookmarkhandler_p.h +++ b/src/filewidgets/kfilebookmarkhandler_p.h @@ -1,69 +1,69 @@ /* This file is part of the KDE libraries Copyright (C) 2002 Carsten Pfeiffer library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation, version 2. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KFILEBOOKMARKHANDLER_H #define KFILEBOOKMARKHANDLER_H #include #include class QMenu; class KFileWidget; /** * Note: Ported to new KBookmarkMenu, but untested */ class KFileBookmarkHandler : public QObject, public KBookmarkOwner { Q_OBJECT public: - KFileBookmarkHandler(KFileWidget *widget); - ~KFileBookmarkHandler(); + explicit KFileBookmarkHandler(KFileWidget *widget); + ~KFileBookmarkHandler() Q_DECL_OVERRIDE; QMenu *popupMenu(); // KBookmarkOwner interface: QString currentTitle() const Q_DECL_OVERRIDE; QUrl currentUrl() const Q_DECL_OVERRIDE; QString currentIcon() const Q_DECL_OVERRIDE; QMenu *menu() const { return m_menu; } public Q_SLOTS: void openBookmark(const KBookmark &bm, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; Q_SIGNALS: void openUrl(const QString &url); private: void importOldBookmarks(const QString &path, KBookmarkManager *manager); KFileWidget *m_widget; QMenu *m_menu; KBookmarkMenu *m_bookmarkMenu; private: class KFileBookmarkHandlerPrivate; KFileBookmarkHandlerPrivate *d; }; #endif // KFILEBOOKMARKHANDLER_H diff --git a/src/filewidgets/kfilecopytomenu.h b/src/filewidgets/kfilecopytomenu.h index 2ebed08a..d396d32b 100644 --- a/src/filewidgets/kfilecopytomenu.h +++ b/src/filewidgets/kfilecopytomenu.h @@ -1,91 +1,91 @@ /* Copyright 2008, 2015 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KFILECOPYTOMENU_H #define KFILECOPYTOMENU_H #include #include #include class QMenu; class KFileCopyToMenuPrivate; /** * @class KFileCopyToMenu kfilecopytomenu.h * * This class adds "Copy To" and "Move To" submenus to a popupmenu. */ class KIOFILEWIDGETS_EXPORT KFileCopyToMenu : public QObject { Q_OBJECT public: /** * Creates a KFileCopyToMenu instance * Note that this instance (and the widget) must stay alive for at least as * long as the popupmenu; it has the slots for the actions created by addActionsTo. * * @param parentWidget parent widget for the file dialog and message boxes. * The parentWidget also serves as a parent for this object. */ - KFileCopyToMenu(QWidget *parentWidget); + explicit KFileCopyToMenu(QWidget *parentWidget); /** * Destructor */ ~KFileCopyToMenu(); /** * Sets the URLs which the actions apply to. */ void setUrls(const QList &urls); /** * If setReadOnly(true) is called, the "Move To" submenu will not appear. */ void setReadOnly(bool ro); /** * Generate the actions and submenus, and adds them to the @p menu. * All actions are created as children of the menu. */ void addActionsTo(QMenu *menu) const; /** * Enables or disables automatic error handling with message boxes. * When called with true, a messagebox is shown in case of an error during a copy or move. * When called with false, the application should connect to the error signal instead. * Auto error handling is disabled by default. */ void setAutoErrorHandlingEnabled(bool b); Q_SIGNALS: /** * Emitted when the copy or move job fails. * @param errorCode the KIO job error code * @param message the error message to show the user */ void error(int errorCode, const QString &message); private: KFileCopyToMenuPrivate *const d; }; #endif diff --git a/src/filewidgets/kfilecustomdialog.h b/src/filewidgets/kfilecustomdialog.h index 5906ae31..4d4dfaa1 100644 --- a/src/filewidgets/kfilecustomdialog.h +++ b/src/filewidgets/kfilecustomdialog.h @@ -1,91 +1,91 @@ /* This file is part of the KDE libraries Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com. Work sponsored by the LiMux project of the city of Munich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2, as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KFILECUSTOMDIALOG_H #define KFILECUSTOMDIALOG_H #include "kiofilewidgets_export.h" #include "kfilewidget.h" #include class KFileWidget; class KFileCustomDialogPrivate; /** * This class implement a custom file dialog. * It uses a KFileWidget and allows the application to provide a custom widget. * @since 5.42 */ class KIOFILEWIDGETS_EXPORT KFileCustomDialog : public QDialog { Q_OBJECT public: explicit KFileCustomDialog(QWidget *parent = nullptr); - ~KFileCustomDialog(); + ~KFileCustomDialog() Q_DECL_OVERRIDE; /** * Sets the directory to view. * * @param url URL to show. */ void setUrl(const QUrl &url); /** * Set a custom widget that should be added to the file dialog. * @param widget A widget, or a widget of widgets, for displaying custom * data in the file widget. This can be used, for example, to * display a check box with the caption "Open as read-only". * When creating this widget, you don't need to specify a parent, * since the widget's parent will be set automatically by KFileWidget. */ void setCustomWidget(QWidget *widget); /** * @brief fileWidget * @return the filewidget used inside this dialog */ KFileWidget *fileWidget() const; /** * Sets the operational mode of the filedialog to @p Saving, @p Opening * or @p Other. This will set some flags that are specific to loading * or saving files. E.g. setKeepLocation() makes mostly sense for * a save-as dialog. So setOperationMode( KFileWidget::Saving ); sets * setKeepLocation for example. * * The mode @p Saving, together with a default filter set via * setMimeFilter() will make the filter combobox read-only. * * The default mode is @p Opening. * * Call this method right after instantiating KFileWidget. * * @see operationMode * @see KFileWidget::OperationMode */ void setOperationMode(KFileWidget::OperationMode op); public Q_SLOTS: void accept() override; private: KFileCustomDialogPrivate *const d; }; #endif // KFILECUSTOMDIALOG_H diff --git a/src/filewidgets/kfilefiltercombo.h b/src/filewidgets/kfilefiltercombo.h index bb8dea50..87aaa41d 100644 --- a/src/filewidgets/kfilefiltercombo.h +++ b/src/filewidgets/kfilefiltercombo.h @@ -1,124 +1,124 @@ /* This file is part of the KDE libraries Copyright (C) Stephan Kulow This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KFILEFILTERCOMBO_H #define KFILEFILTERCOMBO_H #include "kiofilewidgets_export.h" #include #include /** * @class KFileFilterCombo kfilefiltercombo.h * * File filter combo box. */ class KIOFILEWIDGETS_EXPORT KFileFilterCombo : public KComboBox { Q_OBJECT public: /** * Creates a new filter combo box. * * @param parent The parent widget. */ - KFileFilterCombo(QWidget *parent = nullptr); + explicit KFileFilterCombo(QWidget *parent = nullptr); /** * Destroys the filter combo box. */ - ~KFileFilterCombo(); + ~KFileFilterCombo() Q_DECL_OVERRIDE; /** * Sets the @p filter string. */ void setFilter(const QString &filter); /** * @returns the current filter, either something like "*.cpp *.h" * or the current mimetype, like "text/html", or a list of those, like " "text/html text/plain image/png", all separated with one space. */ QString currentFilter() const; /** * Sets the current filter. Filter must match one of the filter items * passed before to this widget. */ void setCurrentFilter(const QString &filter); /** * Sets a list of mimetypes. * If @p defaultType is set, it will be set as the current item. * Otherwise, a first item showing all the mimetypes will be created. */ void setMimeFilter(const QStringList &types, const QString &defaultType); /** * @return true if the filter's first item is the list of all mimetypes */ bool showsAllTypes() const; /** * This method allows you to set a default-filter, that is used when an * empty filter is set. Make sure you call this before calling * setFilter(). * * By default, this is set to i18n("*|All Files") * @see defaultFilter */ void setDefaultFilter(const QString &filter); /** * @return the default filter, used when an empty filter is set. * @see setDefaultFilter */ QString defaultFilter() const; /** * @return all filters (this can be a list of patterns or a list of mimetypes) */ QStringList filters() const; /** * Returns true if the filter has been set using setMimeFilter(). * @since 4.6.1 */ bool isMimeFilter() const; protected: bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; Q_SIGNALS: /** * This signal is emitted whenever the filter has been changed. */ void filterChanged(); private: class Private; Private *const d; Q_PRIVATE_SLOT(d, void _k_slotFilterChanged()) }; #endif diff --git a/src/filewidgets/kfileplacesmodel.h b/src/filewidgets/kfileplacesmodel.h index af5f459b..b63e259f 100644 --- a/src/filewidgets/kfileplacesmodel.h +++ b/src/filewidgets/kfileplacesmodel.h @@ -1,229 +1,229 @@ /* This file is part of the KDE project Copyright (C) 2007 Kevin Ottens Copyright (C) 2007 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KFILEPLACESMODEL_H #define KFILEPLACESMODEL_H #include "kiofilewidgets_export.h" #include #include #include #include class QMimeData; class QAction; /** * @class KFilePlacesModel kfileplacesmodel.h * * This class is a list view model. Each entry represents a "place" * where user can access files. Only revelant when * used with QListView or QTableView. */ class KIOFILEWIDGETS_EXPORT KFilePlacesModel : public QAbstractItemModel { Q_OBJECT public: enum AdditionalRoles { UrlRole = 0x069CD12B, HiddenRole = 0x0741CAAC, SetupNeededRole = 0x059A935D, FixedDeviceRole = 0x332896C1, CapacityBarRecommendedRole = 0x1548C5C4, GroupRole = 0x0a5b64ee, /// @since 5.41 IconNameRole = 0x00a45c00, GroupHiddenRole = 0x21a4b936 }; /// @since 5.42 enum GroupType { PlacesType, RemoteType, RecentlySavedType, SearchForType, DevicesType, RemovableDevicesType, UnknownType }; - KFilePlacesModel(QObject *parent = nullptr); + explicit KFilePlacesModel(QObject *parent = nullptr); /** * @brief Construct a new KFilePlacesModel with an alternativeApplicationName * @param alternativeApplicationName This value will be used to filter bookmarks in addition to the actual application name * @param parent Parent object * @since 5.43 * @todo kf6: merge contstructors */ KFilePlacesModel(const QString &alternativeApplicationName, QObject *parent = nullptr); - ~KFilePlacesModel(); + ~KFilePlacesModel() Q_DECL_OVERRIDE; QUrl url(const QModelIndex &index) const; bool setupNeeded(const QModelIndex &index) const; QIcon icon(const QModelIndex &index) const; QString text(const QModelIndex &index) const; bool isHidden(const QModelIndex &index) const; /// @since 5.42 bool isGroupHidden(const GroupType type) const; /// @since 5.42 bool isGroupHidden(const QModelIndex &index) const; bool isDevice(const QModelIndex &index) const; Solid::Device deviceForIndex(const QModelIndex &index) const; KBookmark bookmarkForIndex(const QModelIndex &index) const; /// @since 5.42 GroupType groupType(const QModelIndex &index) const; QModelIndexList groupIndexes(const GroupType type) const; QAction *teardownActionForIndex(const QModelIndex &index) const; QAction *ejectActionForIndex(const QModelIndex &index) const; void requestTeardown(const QModelIndex &index); void requestEject(const QModelIndex &index); void requestSetup(const QModelIndex &index); void addPlace(const QString &text, const QUrl &url, const QString &iconName = QString(), const QString &appName = QString()); void addPlace(const QString &text, const QUrl &url, const QString &iconName, const QString &appName, const QModelIndex &after); void editPlace(const QModelIndex &index, const QString &text, const QUrl &url, const QString &iconName = QString(), const QString &appName = QString()); void removePlace(const QModelIndex &index) const; void setPlaceHidden(const QModelIndex &index, bool hidden); /// @since 5.42 void setGroupHidden(const GroupType type, bool hidden); /** * @brief Move place at @p itemRow to a position before @p row * @since 5.41 */ bool movePlace(int itemRow, int row); int hiddenCount() const; /** * @brief Get a visible data based on Qt role for the given index. * Return the device information for the give index. * * @param index The QModelIndex which contains the row, column to fetch the data. * @param role The Interview data role(ex: Qt::DisplayRole). * * @return the data for the given index and role. */ QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; /** * @brief Get the children model index for the given row and column. */ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /** * @brief Get the parent QModelIndex for the given model child. */ QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE; /** * @brief Get the number of rows for a model index. */ int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /** * @brief Get the number of columns for a model index. */ int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; /** * Returns the closest item for the URL \a url. * The closest item is defined as item which is equal to * the URL or at least is a parent URL. If there are more than * one possible parent URL candidates, the item which covers * the bigger range of the URL is returned. * * Example: the url is '/home/peter/Documents/Music'. * Available items are: * - /home/peter * - /home/peter/Documents * * The returned item will the one for '/home/peter/Documents'. */ QModelIndex closestItem(const QUrl &url) const; Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE; Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; QStringList mimeTypes() const Q_DECL_OVERRIDE; QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE; /** * @brief Reload bookmark information * @since 5.41 */ void refresh() const; /** * @brief Converts the URL, which contains "virtual" URLs for system-items like * "timeline:/lastmonth" into a Query-URL "timeline:/2017-10" * that will be handled by the corresponding IO-slave. * Virtual URLs for bookmarks are used to be independent from * internal format changes. * @param an url * @return the converted URL, which can be handled by an ioslave * @since 5.41 */ static QUrl convertedUrl(const QUrl &url); /** * Set the URL schemes that the file widget should allow navigating to. * * If the returned list is empty, all schemes are supported. Examples for * schemes are @c "file" or @c "ftp". * * @sa QFileDialog::setSupportedSchemes * @since 5.43 */ void setSupportedSchemes(const QStringList &schemes); /** * Returns the URL schemes that the file widget should allow navigating to. * * If the returned list is empty, all schemes are supported. * * @sa QFileDialog::supportedSchemes * @since 5.43 */ QStringList supportedSchemes() const; Q_SIGNALS: void errorMessage(const QString &message); void setupDone(const QModelIndex &index, bool success); void groupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden); private: Q_PRIVATE_SLOT(d, void _k_initDeviceList()) Q_PRIVATE_SLOT(d, void _k_deviceAdded(const QString &)) Q_PRIVATE_SLOT(d, void _k_deviceRemoved(const QString &)) Q_PRIVATE_SLOT(d, void _k_itemChanged(const QString &)) Q_PRIVATE_SLOT(d, void _k_reloadBookmarks()) Q_PRIVATE_SLOT(d, void _k_storageSetupDone(Solid::ErrorType, QVariant)) Q_PRIVATE_SLOT(d, void _k_storageTeardownDone(Solid::ErrorType, QVariant)) class Private; Private *const d; friend class Private; }; #endif diff --git a/src/filewidgets/kfileplacesview.cpp b/src/filewidgets/kfileplacesview.cpp index d5ba99dd..c658b9df 100644 --- a/src/filewidgets/kfileplacesview.cpp +++ b/src/filewidgets/kfileplacesview.cpp @@ -1,1447 +1,1447 @@ /* This file is part of the KDE project Copyright (C) 2007 Kevin Ottens Copyright (C) 2008 Rafael Fernández López This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kfileplacesview.h" #include "kfileplacesview_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kfileplaceeditdialog.h" #include "kfileplacesmodel.h" #define LATERAL_MARGIN 4 #define CAPACITYBAR_HEIGHT 6 class KFilePlacesViewDelegate : public QAbstractItemDelegate { Q_OBJECT public: - KFilePlacesViewDelegate(KFilePlacesView *parent); - virtual ~KFilePlacesViewDelegate(); + explicit KFilePlacesViewDelegate(KFilePlacesView *parent); + ~KFilePlacesViewDelegate() Q_DECL_OVERRIDE; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE; int iconSize() const; void setIconSize(int newSize); void addAppearingItem(const QModelIndex &index); void setAppearingItemProgress(qreal value); void addDisappearingItem(const QModelIndex &index); void addDisappearingItemGroup(const QModelIndex &index); void setDisappearingItemProgress(qreal value); void setShowHoverIndication(bool show); void addFadeAnimation(const QModelIndex &index, QTimeLine *timeLine); void removeFadeAnimation(const QModelIndex &index); QModelIndex indexForFadeAnimation(QTimeLine *timeLine) const; QTimeLine *fadeAnimationForIndex(const QModelIndex &index) const; qreal contentsOpacity(const QModelIndex &index) const; bool pointIsHeaderArea(const QPoint &pos); void startDrag(); int sectionHeaderHeight() const; private: QString groupNameFromIndex(const QModelIndex &index) const; QModelIndex previousVisibleIndex(const QModelIndex &index) const; bool indexIsSectionHeader(const QModelIndex &index) const; void drawSectionHeader(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; QColor textColor(const QStyleOption &option) const; QColor baseColor(const QStyleOption &option) const; QColor mixedColor(const QColor &c1, const QColor &c2, int c1Percent) const; KFilePlacesView *m_view; int m_iconSize; QList m_appearingItems; int m_appearingIconSize; qreal m_appearingOpacity; QList m_disappearingItems; int m_disappearingIconSize; qreal m_disappearingOpacity; bool m_showHoverIndication; mutable bool m_dragStarted; QMap m_timeLineMap; QMap m_timeLineInverseMap; }; KFilePlacesViewDelegate::KFilePlacesViewDelegate(KFilePlacesView *parent) : QAbstractItemDelegate(parent), m_view(parent), m_iconSize(48), m_appearingIconSize(0), m_appearingOpacity(0.0), m_disappearingIconSize(0), m_disappearingOpacity(0.0), m_showHoverIndication(true), m_dragStarted(false) { } KFilePlacesViewDelegate::~KFilePlacesViewDelegate() { } QSize KFilePlacesViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { int iconSize = m_iconSize; if (m_appearingItems.contains(index)) { iconSize = m_appearingIconSize; } else if (m_disappearingItems.contains(index)) { iconSize = m_disappearingIconSize; } int height = option.fontMetrics.height() / 2 + qMax(iconSize, option.fontMetrics.height()); if (indexIsSectionHeader(index)) { height += sectionHeaderHeight(); } return QSize(option.rect.width(), height); } void KFilePlacesViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->save(); QStyleOptionViewItem opt = option; // draw header when necessary if (indexIsSectionHeader(index)) { // If we are drawing the floating element used by drag/drop, do not draw the header if (!m_dragStarted) { drawSectionHeader(painter, opt, index); } // Move the target rect to the actual item rect const int headerHeight = sectionHeaderHeight(); opt.rect.translate(0, headerHeight); opt.rect.setHeight(opt.rect.height() - headerHeight); } m_dragStarted = false; // draw item if (m_appearingItems.contains(index)) { painter->setOpacity(m_appearingOpacity); } else if (m_disappearingItems.contains(index)) { painter->setOpacity(m_disappearingOpacity); } if (!m_showHoverIndication) { opt.state &= ~QStyle::State_MouseOver; } QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter); const KFilePlacesModel *placesModel = static_cast(index.model()); bool isLTR = opt.direction == Qt::LeftToRight; QIcon icon = index.model()->data(index, Qt::DecorationRole).value(); QPixmap pm = icon.pixmap(m_iconSize, m_iconSize, (opt.state & QStyle::State_Selected) && (opt.state & QStyle::State_Active) ? QIcon::Selected : QIcon::Normal); QPoint point(isLTR ? opt.rect.left() + LATERAL_MARGIN : opt.rect.right() - LATERAL_MARGIN - m_iconSize, opt.rect.top() + (opt.rect.height() - m_iconSize) / 2); painter->drawPixmap(point, pm); if (opt.state & QStyle::State_Selected) { QPalette::ColorGroup cg = QPalette::Active; if (!(opt.state & QStyle::State_Enabled)) { cg = QPalette::Disabled; } else if (!(opt.state & QStyle::State_Active)) { cg = QPalette::Inactive; } painter->setPen(opt.palette.color(cg, QPalette::HighlightedText)); } QRect rectText; bool drawCapacityBar = false; if (placesModel->data(index, KFilePlacesModel::CapacityBarRecommendedRole).toBool()) { const QUrl url = placesModel->url(index); if (url.isLocalFile() && contentsOpacity(index) > 0) { const QString mountPointPath = url.toLocalFile(); const KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mountPointPath); drawCapacityBar = info.size() != 0; if (drawCapacityBar) { painter->save(); painter->setOpacity(painter->opacity() * contentsOpacity(index)); int height = opt.fontMetrics.height() + CAPACITYBAR_HEIGHT; rectText = QRect(isLTR ? m_iconSize + LATERAL_MARGIN * 2 + opt.rect.left() : 0, opt.rect.top() + (opt.rect.height() / 2 - height / 2), opt.rect.width() - m_iconSize - LATERAL_MARGIN * 2, opt.fontMetrics.height()); painter->drawText(rectText, Qt::AlignLeft | Qt::AlignTop, opt.fontMetrics.elidedText(index.model()->data(index).toString(), Qt::ElideRight, rectText.width())); QRect capacityRect(isLTR ? rectText.x() : LATERAL_MARGIN, rectText.bottom() - 1, rectText.width() - LATERAL_MARGIN, CAPACITYBAR_HEIGHT); KCapacityBar capacityBar(KCapacityBar::DrawTextInline); capacityBar.setValue((info.used() * 100) / info.size()); capacityBar.drawCapacityBar(painter, capacityRect); painter->restore(); painter->save(); painter->setOpacity(painter->opacity() * (1 - contentsOpacity(index))); } } } rectText = QRect(isLTR ? m_iconSize + LATERAL_MARGIN * 2 + opt.rect.left() : 0, opt.rect.top(), opt.rect.width() - m_iconSize - LATERAL_MARGIN * 2, opt.rect.height()); painter->drawText(rectText, Qt::AlignLeft | Qt::AlignVCenter, opt.fontMetrics.elidedText(index.model()->data(index).toString(), Qt::ElideRight, rectText.width())); if (drawCapacityBar) { painter->restore(); } painter->restore(); } int KFilePlacesViewDelegate::iconSize() const { return m_iconSize; } void KFilePlacesViewDelegate::setIconSize(int newSize) { m_iconSize = newSize; } void KFilePlacesViewDelegate::addAppearingItem(const QModelIndex &index) { m_appearingItems << index; } void KFilePlacesViewDelegate::setAppearingItemProgress(qreal value) { if (value <= 0.25) { m_appearingOpacity = 0.0; m_appearingIconSize = iconSize() * value * 4; if (m_appearingIconSize >= m_iconSize) { m_appearingIconSize = m_iconSize; } } else { m_appearingIconSize = m_iconSize; m_appearingOpacity = (value - 0.25) * 4 / 3; if (value >= 1.0) { m_appearingItems.clear(); } } } void KFilePlacesViewDelegate::addDisappearingItem(const QModelIndex &index) { m_disappearingItems << index; } void KFilePlacesViewDelegate::addDisappearingItemGroup(const QModelIndex &index) { const KFilePlacesModel *placesModel = static_cast(index.model()); const QModelIndexList indexesGroup = placesModel->groupIndexes(placesModel->groupType(index)); m_disappearingItems.reserve(m_disappearingItems.count() + indexesGroup.count()); std::transform(indexesGroup.begin(), indexesGroup.end(), std::back_inserter(m_disappearingItems), [](const QModelIndex &idx){ return QPersistentModelIndex(idx); }); } void KFilePlacesViewDelegate::setDisappearingItemProgress(qreal value) { value = 1.0 - value; if (value <= 0.25) { m_disappearingOpacity = 0.0; m_disappearingIconSize = iconSize() * value * 4; if (m_disappearingIconSize >= m_iconSize) { m_disappearingIconSize = m_iconSize; } if (value <= 0.0) { m_disappearingItems.clear(); } } else { m_disappearingIconSize = m_iconSize; m_disappearingOpacity = (value - 0.25) * 4 / 3; } } void KFilePlacesViewDelegate::setShowHoverIndication(bool show) { m_showHoverIndication = show; } void KFilePlacesViewDelegate::addFadeAnimation(const QModelIndex &index, QTimeLine *timeLine) { m_timeLineMap.insert(index, timeLine); m_timeLineInverseMap.insert(timeLine, index); } void KFilePlacesViewDelegate::removeFadeAnimation(const QModelIndex &index) { QTimeLine *timeLine = m_timeLineMap.value(index, nullptr); m_timeLineMap.remove(index); m_timeLineInverseMap.remove(timeLine); } QModelIndex KFilePlacesViewDelegate::indexForFadeAnimation(QTimeLine *timeLine) const { return m_timeLineInverseMap.value(timeLine, QModelIndex()); } QTimeLine *KFilePlacesViewDelegate::fadeAnimationForIndex(const QModelIndex &index) const { return m_timeLineMap.value(index, nullptr); } qreal KFilePlacesViewDelegate::contentsOpacity(const QModelIndex &index) const { QTimeLine *timeLine = fadeAnimationForIndex(index); if (timeLine) { return timeLine->currentValue(); } return 0; } bool KFilePlacesViewDelegate::pointIsHeaderArea(const QPoint &pos) { // we only accept drag events starting from item body, ignore drag request from header QModelIndex index = m_view->indexAt(pos); if (!index.isValid()) { return false; } if (indexIsSectionHeader(index)) { const QRect vRect = m_view->visualRect(index); const int delegateY = pos.y() - vRect.y(); if (delegateY <= sectionHeaderHeight()) { return true; } } return false; } void KFilePlacesViewDelegate::startDrag() { m_dragStarted = true; } QString KFilePlacesViewDelegate::groupNameFromIndex(const QModelIndex &index) const { if (index.isValid()) { return index.data(KFilePlacesModel::GroupRole).toString(); } else { return QString(); } } QModelIndex KFilePlacesViewDelegate::previousVisibleIndex(const QModelIndex &index) const { if (index.row() == 0) { return QModelIndex(); } const QAbstractItemModel *model = index.model(); QModelIndex prevIndex = model->index(index.row() - 1, index.column(), index.parent()); while (m_view->isRowHidden(prevIndex.row())) { if (prevIndex.row() == 0) { return QModelIndex(); } prevIndex = model->index(prevIndex.row() - 1, index.column(), index.parent()); } return prevIndex; } bool KFilePlacesViewDelegate::indexIsSectionHeader(const QModelIndex &index) const { if (m_view->isRowHidden(index.row())) { return false; } if (index.row() == 0) { return true; } const auto groupName = groupNameFromIndex(index); const auto previousGroupName = groupNameFromIndex(previousVisibleIndex(index)); return groupName != previousGroupName; } void KFilePlacesViewDelegate::drawSectionHeader(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const KFilePlacesModel *placesModel = static_cast(index.model()); const QString groupLabel = index.data(KFilePlacesModel::GroupRole).toString(); const QString category = placesModel->isGroupHidden(index) ? i18n("%1 (hidden)", groupLabel) : groupLabel; QRect textRect(option.rect); textRect.setLeft(textRect.left() + 3); /* Take spacing into account: The spacing to the previous section compensates for the spacing to the first item.*/ textRect.setY(textRect.y() /* + qMax(2, m_view->spacing()) - qMax(2, m_view->spacing())*/); textRect.setHeight(sectionHeaderHeight()); painter->save(); // based on dolphin colors const QColor c1 = textColor(option); const QColor c2 = baseColor(option); QColor penColor = mixedColor(c1, c2, 60); painter->setPen(penColor); painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, category); painter->restore(); } QColor KFilePlacesViewDelegate::textColor(const QStyleOption &option) const { const QPalette::ColorGroup group = m_view->isActiveWindow() ? QPalette::Active : QPalette::Inactive; return option.palette.color(group, QPalette::WindowText); } QColor KFilePlacesViewDelegate::baseColor(const QStyleOption &option) const { const QPalette::ColorGroup group = m_view->isActiveWindow() ? QPalette::Active : QPalette::Inactive; return option.palette.color(group, QPalette::Window); } QColor KFilePlacesViewDelegate::mixedColor(const QColor& c1, const QColor& c2, int c1Percent) const { Q_ASSERT(c1Percent >= 0 && c1Percent <= 100); const int c2Percent = 100 - c1Percent; return QColor((c1.red() * c1Percent + c2.red() * c2Percent) / 100, (c1.green() * c1Percent + c2.green() * c2Percent) / 100, (c1.blue() * c1Percent + c2.blue() * c2Percent) / 100); } int KFilePlacesViewDelegate::sectionHeaderHeight() const { // Account for the spacing between header and item return QApplication::fontMetrics().height() + qMax(2, m_view->spacing()); } class Q_DECL_HIDDEN KFilePlacesView::Private { public: Private(KFilePlacesView *parent) : q(parent), watcher(new KFilePlacesEventWatcher(q)) { } enum FadeType { FadeIn = 0, FadeOut }; KFilePlacesView *const q; QUrl currentUrl; bool autoResizeItems; bool showAll; bool smoothItemResizing; bool dropOnPlace; bool dragging; Solid::StorageAccess *lastClickedStorage = nullptr; QPersistentModelIndex lastClickedIndex; QRect dropRect; void setCurrentIndex(const QModelIndex &index); void adaptItemSize(); void updateHiddenRows(); bool insertAbove(const QRect &itemRect, const QPoint &pos) const; bool insertBelow(const QRect &itemRect, const QPoint &pos) const; int insertIndicatorHeight(int itemHeight) const; void fadeCapacityBar(const QModelIndex &index, FadeType fadeType); int sectionsCount() const; void addDisappearingItem(KFilePlacesViewDelegate *delegate, const QModelIndex &index); void triggerItemAppearingAnimation(); void triggerItemDisappearingAnimation(); void _k_placeClicked(const QModelIndex &index); void _k_placeEntered(const QModelIndex &index); void _k_placeLeft(const QModelIndex &index); void _k_storageSetupDone(const QModelIndex &index, bool success); void _k_adaptItemsUpdate(qreal value); void _k_itemAppearUpdate(qreal value); void _k_itemDisappearUpdate(qreal value); void _k_enableSmoothItemResizing(); void _k_capacityBarFadeValueChanged(); void _k_triggerDevicePolling(); QTimeLine adaptItemsTimeline; int oldSize, endSize; QTimeLine itemAppearTimeline; QTimeLine itemDisappearTimeline; KFilePlacesEventWatcher *const watcher; KFilePlacesViewDelegate *delegate = nullptr; QTimer pollDevices; int pollingRequestCount; }; KFilePlacesView::KFilePlacesView(QWidget *parent) : QListView(parent), d(new Private(this)) { d->showAll = false; d->smoothItemResizing = false; d->dropOnPlace = false; d->autoResizeItems = true; d->dragging = false; d->lastClickedStorage = nullptr; d->pollingRequestCount = 0; d->delegate = new KFilePlacesViewDelegate(this); setSelectionRectVisible(false); setSelectionMode(SingleSelection); setDragEnabled(true); setAcceptDrops(true); setMouseTracking(true); setDropIndicatorShown(false); setFrameStyle(QFrame::NoFrame); setResizeMode(Adjust); setItemDelegate(d->delegate); QPalette palette = viewport()->palette(); palette.setColor(viewport()->backgroundRole(), Qt::transparent); palette.setColor(viewport()->foregroundRole(), palette.color(QPalette::WindowText)); viewport()->setPalette(palette); connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(_k_placeClicked(QModelIndex))); // Note: Don't connect to the activated() signal, as the behavior when it is // committed depends on the used widget style. The click behavior of // KFilePlacesView should be style independent. connect(&d->adaptItemsTimeline, SIGNAL(valueChanged(qreal)), this, SLOT(_k_adaptItemsUpdate(qreal))); d->adaptItemsTimeline.setDuration(500); d->adaptItemsTimeline.setUpdateInterval(5); d->adaptItemsTimeline.setCurveShape(QTimeLine::EaseInOutCurve); connect(&d->itemAppearTimeline, SIGNAL(valueChanged(qreal)), this, SLOT(_k_itemAppearUpdate(qreal))); d->itemAppearTimeline.setDuration(500); d->itemAppearTimeline.setUpdateInterval(5); d->itemAppearTimeline.setCurveShape(QTimeLine::EaseInOutCurve); connect(&d->itemDisappearTimeline, SIGNAL(valueChanged(qreal)), this, SLOT(_k_itemDisappearUpdate(qreal))); d->itemDisappearTimeline.setDuration(500); d->itemDisappearTimeline.setUpdateInterval(5); d->itemDisappearTimeline.setCurveShape(QTimeLine::EaseInOutCurve); viewport()->installEventFilter(d->watcher); connect(d->watcher, SIGNAL(entryEntered(QModelIndex)), this, SLOT(_k_placeEntered(QModelIndex))); connect(d->watcher, SIGNAL(entryLeft(QModelIndex)), this, SLOT(_k_placeLeft(QModelIndex))); d->pollDevices.setInterval(5000); connect(&d->pollDevices, SIGNAL(timeout()), this, SLOT(_k_triggerDevicePolling())); // FIXME: this is necessary to avoid flashes of black with some widget styles. // could be a bug in Qt (e.g. QAbstractScrollArea) or KFilePlacesView, but has not // yet been tracked down yet. until then, this works and is harmlessly enough. // in fact, some QStyle (Oxygen, Skulpture, others?) do this already internally. // See br #242358 for more information verticalScrollBar()->setAttribute(Qt::WA_OpaquePaintEvent, false); } KFilePlacesView::~KFilePlacesView() { delete d; } void KFilePlacesView::setDropOnPlaceEnabled(bool enabled) { d->dropOnPlace = enabled; } bool KFilePlacesView::isDropOnPlaceEnabled() const { return d->dropOnPlace; } void KFilePlacesView::setAutoResizeItemsEnabled(bool enabled) { d->autoResizeItems = enabled; } bool KFilePlacesView::isAutoResizeItemsEnabled() const { return d->autoResizeItems; } void KFilePlacesView::setUrl(const QUrl &url) { KFilePlacesModel *placesModel = qobject_cast(model()); if (placesModel == nullptr) { return; } QModelIndex index = placesModel->closestItem(url); QModelIndex current = selectionModel()->currentIndex(); if (index.isValid()) { if (current != index && placesModel->isHidden(current) && !d->showAll) { KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); d->addDisappearingItem(delegate, current); } if (current != index && placesModel->isHidden(index) && !d->showAll) { KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->addAppearingItem(index); d->triggerItemAppearingAnimation(); setRowHidden(index.row(), false); } d->currentUrl = url; selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); } else { d->currentUrl = QUrl(); selectionModel()->clear(); } if (!current.isValid()) { d->updateHiddenRows(); } } void KFilePlacesView::setShowAll(bool showAll) { KFilePlacesModel *placesModel = qobject_cast(model()); if (placesModel == nullptr) { return; } d->showAll = showAll; KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); int rowCount = placesModel->rowCount(); QModelIndex current = placesModel->closestItem(d->currentUrl); if (showAll) { d->updateHiddenRows(); for (int i = 0; i < rowCount; ++i) { QModelIndex index = placesModel->index(i, 0); if (index != current && placesModel->isHidden(index)) { delegate->addAppearingItem(index); } } d->triggerItemAppearingAnimation(); } else { for (int i = 0; i < rowCount; ++i) { QModelIndex index = placesModel->index(i, 0); if (index != current && placesModel->isHidden(index)) { delegate->addDisappearingItem(index); } } d->triggerItemDisappearingAnimation(); } } void KFilePlacesView::keyPressEvent(QKeyEvent *event) { QListView::keyPressEvent(event); if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)) { d->_k_placeClicked(currentIndex()); } } void KFilePlacesView::contextMenuEvent(QContextMenuEvent *event) { KFilePlacesModel *placesModel = qobject_cast(model()); if (!placesModel) { return; } KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); QModelIndex index = indexAt(event->pos()); const QString label = placesModel->text(index).replace(QLatin1Char('&'), QLatin1String("&&")); QMenu menu; QAction *edit = nullptr; QAction *hide = nullptr; QAction *emptyTrash = nullptr; QAction *eject = nullptr; QAction *teardown = nullptr; QAction *add = nullptr; QAction *mainSeparator = nullptr; QAction *hideSection = nullptr; const bool clickOverHeader = delegate->pointIsHeaderArea(event->pos()); if (clickOverHeader) { const KFilePlacesModel::GroupType type = placesModel->groupType(index); hideSection = menu.addAction(i18n("Hide Section")); hideSection->setCheckable(true); hideSection->setChecked(placesModel->isGroupHidden(type)); } else if (index.isValid()) { if (!placesModel->isDevice(index)) { if (placesModel->url(index).toString() == QLatin1String("trash:/")) { emptyTrash = menu.addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash")); KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); emptyTrash->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); menu.addSeparator(); } add = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add Entry...")); mainSeparator = menu.addSeparator(); edit = menu.addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18n("&Edit Entry '%1'...", label)); } else { eject = placesModel->ejectActionForIndex(index); if (eject != nullptr) { eject->setParent(&menu); menu.addAction(eject); } teardown = placesModel->teardownActionForIndex(index); if (teardown != nullptr) { teardown->setParent(&menu); menu.addAction(teardown); } if (teardown != nullptr || eject != nullptr) { mainSeparator = menu.addSeparator(); } } if (add == nullptr) { add = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add Entry...")); } hide = menu.addAction(i18n("&Hide Entry '%1'", label)); hide->setCheckable(true); hide->setChecked(placesModel->isHidden(index)); // if a parent is hidden no interaction should be possible with children, show it first to do so hide->setEnabled(!placesModel->isGroupHidden(placesModel->groupType(index))); } else { add = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18n("Add Entry...")); } QAction *showAll = nullptr; if (placesModel->hiddenCount() > 0) { showAll = new QAction(i18n("&Show All Entries"), &menu); showAll->setCheckable(true); showAll->setChecked(d->showAll); if (mainSeparator == nullptr) { mainSeparator = menu.addSeparator(); } menu.insertAction(mainSeparator, showAll); } QAction *remove = nullptr; if (!clickOverHeader && index.isValid() && !placesModel->isDevice(index)) { remove = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("&Remove Entry '%1'", label)); } menu.addActions(actions()); if (menu.isEmpty()) { return; } QAction *result = menu.exec(event->globalPos()); if (emptyTrash && (result == emptyTrash)) { KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(window()); if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { KIO::Job* job = KIO::emptyTrash(); KJobWidgets::setWindow(job, window()); job->uiDelegate()->setAutoErrorHandlingEnabled(true); } } else if (edit && (result == edit)) { KBookmark bookmark = placesModel->bookmarkForIndex(index); QUrl url = bookmark.url(); QString label = bookmark.text(); QString iconName = bookmark.icon(); bool appLocal = !bookmark.metaDataItem(QStringLiteral("OnlyInApp")).isEmpty(); if (KFilePlaceEditDialog::getInformation(true, url, label, iconName, false, appLocal, 64, this)) { QString appName; if (appLocal) { appName = QCoreApplication::instance()->applicationName(); } placesModel->editPlace(index, label, url, iconName, appName); } } else if (remove && (result == remove)) { placesModel->removePlace(index); } else if (hideSection && (result == hideSection)) { const KFilePlacesModel::GroupType type = placesModel->groupType(index); placesModel->setGroupHidden(type, hideSection->isChecked()); if (!d->showAll && hideSection->isChecked()) { delegate->addDisappearingItemGroup(index); d->triggerItemDisappearingAnimation(); } } else if (hide && (result == hide)) { placesModel->setPlaceHidden(index, hide->isChecked()); QModelIndex current = placesModel->closestItem(d->currentUrl); if (index != current && !d->showAll && hide->isChecked()) { delegate->addDisappearingItem(index); d->triggerItemDisappearingAnimation(); } } else if (showAll && (result == showAll)) { setShowAll(showAll->isChecked()); } else if (teardown && (result == teardown)) { placesModel->requestTeardown(index); } else if (eject && (result == eject)) { placesModel->requestEject(index); } else if (add && (result == add)) { QUrl url = d->currentUrl; QString label; QString iconName = QStringLiteral("folder"); bool appLocal = true; if (KFilePlaceEditDialog::getInformation(true, url, label, iconName, true, appLocal, 64, this)) { QString appName; if (appLocal) { appName = QCoreApplication::instance()->applicationName(); } placesModel->addPlace(label, url, iconName, appName, index); } } index = placesModel->closestItem(d->currentUrl); selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); } void KFilePlacesView::resizeEvent(QResizeEvent *event) { QListView::resizeEvent(event); d->adaptItemSize(); } void KFilePlacesView::showEvent(QShowEvent *event) { QListView::showEvent(event); QTimer::singleShot(100, this, SLOT(_k_enableSmoothItemResizing())); } void KFilePlacesView::hideEvent(QHideEvent *event) { QListView::hideEvent(event); d->smoothItemResizing = false; } void KFilePlacesView::dragEnterEvent(QDragEnterEvent *event) { QListView::dragEnterEvent(event); d->dragging = true; KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(false); d->dropRect = QRect(); } void KFilePlacesView::dragLeaveEvent(QDragLeaveEvent *event) { QListView::dragLeaveEvent(event); d->dragging = false; KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(true); setDirtyRegion(d->dropRect); } void KFilePlacesView::dragMoveEvent(QDragMoveEvent *event) { QListView::dragMoveEvent(event); // update the drop indicator const QPoint pos = event->pos(); const QModelIndex index = indexAt(pos); setDirtyRegion(d->dropRect); if (index.isValid()) { const QRect rect = visualRect(index); const int gap = d->insertIndicatorHeight(rect.height()); if (d->insertAbove(rect, pos)) { // indicate that the item will be inserted above the current place d->dropRect = QRect(rect.left(), rect.top() - gap / 2, rect.width(), gap); } else if (d->insertBelow(rect, pos)) { // indicate that the item will be inserted below the current place d->dropRect = QRect(rect.left(), rect.bottom() + 1 - gap / 2, rect.width(), gap); } else { // indicate that the item be dropped above the current place d->dropRect = rect; } } setDirtyRegion(d->dropRect); } void KFilePlacesView::dropEvent(QDropEvent *event) { const QPoint pos = event->pos(); const QModelIndex index = indexAt(pos); if (index.isValid()) { const QRect rect = visualRect(index); if (!d->insertAbove(rect, pos) && !d->insertBelow(rect, pos)) { KFilePlacesModel *placesModel = qobject_cast(model()); Q_ASSERT(placesModel != nullptr); emit urlsDropped(placesModel->url(index), event, this); event->acceptProposedAction(); } } QListView::dropEvent(event); d->dragging = false; KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(true); } void KFilePlacesView::paintEvent(QPaintEvent *event) { QListView::paintEvent(event); if (d->dragging && !d->dropRect.isEmpty()) { // draw drop indicator QPainter painter(viewport()); const QModelIndex index = indexAt(d->dropRect.topLeft()); const QRect itemRect = visualRect(index); const bool drawInsertIndicator = !d->dropOnPlace || d->dropRect.height() <= d->insertIndicatorHeight(itemRect.height()); if (drawInsertIndicator) { // draw indicator for inserting items QBrush blendedBrush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight); QColor color = blendedBrush.color(); const int y = (d->dropRect.top() + d->dropRect.bottom()) / 2; const int thickness = d->dropRect.height() / 2; Q_ASSERT(thickness >= 1); int alpha = 255; const int alphaDec = alpha / (thickness + 1); for (int i = 0; i < thickness; i++) { color.setAlpha(alpha); alpha -= alphaDec; painter.setPen(color); painter.drawLine(d->dropRect.left(), y - i, d->dropRect.right(), y - i); painter.drawLine(d->dropRect.left(), y + i, d->dropRect.right(), y + i); } } else { // draw indicator for copying/moving/linking to items QStyleOptionViewItem opt; opt.initFrom(this); opt.rect = itemRect; opt.state = QStyle::State_Enabled | QStyle::State_MouseOver; style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, &painter, this); } } } void KFilePlacesView::startDrag(Qt::DropActions supportedActions) { KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->startDrag(); QListView::startDrag(supportedActions); } void KFilePlacesView::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); // does not accept drags from section header area if (delegate->pointIsHeaderArea(event->pos())) { return; } } QListView::mousePressEvent(event); } void KFilePlacesView::setModel(QAbstractItemModel *model) { QListView::setModel(model); d->updateHiddenRows(); // Uses Qt::QueuedConnection to delay the time when the slot will be // called. In case of an item move the remove+add will be done before // we adapt the item size (otherwise we'd get it wrong as we'd execute // it after the remove only). connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(adaptItemSize()), Qt::QueuedConnection); connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), d->watcher, SLOT(currentIndexChanged(QModelIndex))); } void KFilePlacesView::rowsInserted(const QModelIndex &parent, int start, int end) { QListView::rowsInserted(parent, start, end); setUrl(d->currentUrl); KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); KFilePlacesModel *placesModel = static_cast(model()); for (int i = start; i <= end; ++i) { QModelIndex index = placesModel->index(i, 0, parent); if (d->showAll || !placesModel->isHidden(index)) { delegate->addAppearingItem(index); d->triggerItemAppearingAnimation(); } else { setRowHidden(i, true); } } d->triggerItemAppearingAnimation(); d->adaptItemSize(); } QSize KFilePlacesView::sizeHint() const { KFilePlacesModel *placesModel = qobject_cast(model()); if (!placesModel) { return QListView::sizeHint(); } const int height = QListView::sizeHint().height(); QFontMetrics fm = d->q->fontMetrics(); int textWidth = 0; for (int i = 0; i < placesModel->rowCount(); ++i) { QModelIndex index = placesModel->index(i, 0); if (!placesModel->isHidden(index)) { textWidth = qMax(textWidth, fm.width(index.data(Qt::DisplayRole).toString())); } } const int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small) + 3 * LATERAL_MARGIN; return QSize(iconSize + textWidth + fm.height() / 2, height); } void KFilePlacesView::Private::addDisappearingItem(KFilePlacesViewDelegate *delegate, const QModelIndex &index) { delegate->addDisappearingItem(index); if (itemDisappearTimeline.state() != QTimeLine::Running) { delegate->setDisappearingItemProgress(0.0); itemDisappearTimeline.start(); } } void KFilePlacesView::Private::setCurrentIndex(const QModelIndex &index) { KFilePlacesModel *placesModel = qobject_cast(q->model()); if (placesModel == nullptr) { return; } QUrl url = placesModel->url(index); if (url.isValid()) { currentUrl = url; updateHiddenRows(); emit q->urlChanged(KFilePlacesModel::convertedUrl(url)); if (showAll) { q->setShowAll(false); } } else { q->setUrl(currentUrl); } } void KFilePlacesView::Private::adaptItemSize() { KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); if (!autoResizeItems) { const int size = q->iconSize().width(); // Assume width == height delegate->setIconSize(size); q->scheduleDelayedItemsLayout(); return; } KFilePlacesModel *placesModel = qobject_cast(q->model()); if (placesModel == nullptr) { return; } int rowCount = placesModel->rowCount(); if (!showAll) { rowCount -= placesModel->hiddenCount(); QModelIndex current = placesModel->closestItem(currentUrl); if (placesModel->isHidden(current)) { rowCount++; } } if (rowCount == 0) { return; // We've nothing to display anyway } const int minSize = IconSize(KIconLoader::Small); const int maxSize = 64; int textWidth = 0; QFontMetrics fm = q->fontMetrics(); for (int i = 0; i < placesModel->rowCount(); ++i) { QModelIndex index = placesModel->index(i, 0); if (!placesModel->isHidden(index)) { textWidth = qMax(textWidth, fm.width(index.data(Qt::DisplayRole).toString())); } } const int margin = q->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, q) + 1; const int maxWidth = q->viewport()->width() - textWidth - 4 * margin - 1; const int totalItemsHeight = (fm.height() / 2) * rowCount; const int totalSectionsHeight = delegate->sectionHeaderHeight() * sectionsCount(); const int maxHeight = ((q->height() - totalSectionsHeight - totalItemsHeight) / rowCount) - 1; int size = qMin(maxHeight, maxWidth); if (size < minSize) { size = minSize; } else if (size > maxSize) { size = maxSize; } else { // Make it a multiple of 16 size &= ~0xf; } if (size == delegate->iconSize()) { return; } if (smoothItemResizing) { oldSize = delegate->iconSize(); endSize = size; if (adaptItemsTimeline.state() != QTimeLine::Running) { adaptItemsTimeline.start(); } } else { delegate->setIconSize(size); q->scheduleDelayedItemsLayout(); } } void KFilePlacesView::Private::updateHiddenRows() { KFilePlacesModel *placesModel = qobject_cast(q->model()); if (placesModel == nullptr) { return; } int rowCount = placesModel->rowCount(); QModelIndex current = placesModel->closestItem(currentUrl); for (int i = 0; i < rowCount; ++i) { QModelIndex index = placesModel->index(i, 0); if (index != current && placesModel->isHidden(index) && !showAll) { q->setRowHidden(i, true); } else { q->setRowHidden(i, false); } } adaptItemSize(); } bool KFilePlacesView::Private::insertAbove(const QRect &itemRect, const QPoint &pos) const { if (dropOnPlace) { return pos.y() < itemRect.top() + insertIndicatorHeight(itemRect.height()) / 2; } return pos.y() < itemRect.top() + (itemRect.height() / 2); } bool KFilePlacesView::Private::insertBelow(const QRect &itemRect, const QPoint &pos) const { if (dropOnPlace) { return pos.y() > itemRect.bottom() - insertIndicatorHeight(itemRect.height()) / 2; } return pos.y() >= itemRect.top() + (itemRect.height() / 2); } int KFilePlacesView::Private::insertIndicatorHeight(int itemHeight) const { const int min = 4; const int max = 12; int height = itemHeight / 4; if (height < min) { height = min; } else if (height > max) { height = max; } return height; } void KFilePlacesView::Private::fadeCapacityBar(const QModelIndex &index, FadeType fadeType) { QTimeLine *timeLine = delegate->fadeAnimationForIndex(index); delete timeLine; delegate->removeFadeAnimation(index); timeLine = new QTimeLine(250, q); connect(timeLine, SIGNAL(valueChanged(qreal)), q, SLOT(_k_capacityBarFadeValueChanged())); if (fadeType == FadeIn) { timeLine->setDirection(QTimeLine::Forward); timeLine->setCurrentTime(0); } else { timeLine->setDirection(QTimeLine::Backward); timeLine->setCurrentTime(250); } delegate->addFadeAnimation(index, timeLine); timeLine->start(); } int KFilePlacesView::Private::sectionsCount() const { int count = 0; QString prevSection; const int rowCount = q->model()->rowCount(); for(int i = 0; i < rowCount; i++) { if (!q->isRowHidden(i)) { const QModelIndex index = q->model()->index(i, 0); const QString sectionName = index.data(KFilePlacesModel::GroupRole).toString(); if (prevSection != sectionName) { prevSection = sectionName; count++; } } } return count; } void KFilePlacesView::Private::triggerItemAppearingAnimation() { if (itemAppearTimeline.state() != QTimeLine::Running) { delegate->setAppearingItemProgress(0.0); itemAppearTimeline.start(); } } void KFilePlacesView::Private::triggerItemDisappearingAnimation() { if (itemDisappearTimeline.state() != QTimeLine::Running) { delegate->setDisappearingItemProgress(0.0); itemDisappearTimeline.start(); } } void KFilePlacesView::Private::_k_placeClicked(const QModelIndex &index) { KFilePlacesModel *placesModel = qobject_cast(q->model()); if (placesModel == nullptr) { return; } lastClickedIndex = QPersistentModelIndex(); if (placesModel->setupNeeded(index)) { QObject::connect(placesModel, SIGNAL(setupDone(QModelIndex,bool)), q, SLOT(_k_storageSetupDone(QModelIndex,bool))); lastClickedIndex = index; placesModel->requestSetup(index); return; } setCurrentIndex(index); } void KFilePlacesView::Private::_k_placeEntered(const QModelIndex &index) { fadeCapacityBar(index, FadeIn); pollingRequestCount++; if (pollingRequestCount == 1) { pollDevices.start(); } } void KFilePlacesView::Private::_k_placeLeft(const QModelIndex &index) { fadeCapacityBar(index, FadeOut); pollingRequestCount--; if (!pollingRequestCount) { pollDevices.stop(); } } void KFilePlacesView::Private::_k_storageSetupDone(const QModelIndex &index, bool success) { if (index != lastClickedIndex) { return; } KFilePlacesModel *placesModel = qobject_cast(q->model()); if (placesModel) { QObject::disconnect(placesModel, SIGNAL(setupDone(QModelIndex,bool)), q, SLOT(_k_storageSetupDone(QModelIndex,bool))); } if (success) { setCurrentIndex(lastClickedIndex); } else { q->setUrl(currentUrl); } lastClickedIndex = QPersistentModelIndex(); } void KFilePlacesView::Private::_k_adaptItemsUpdate(qreal value) { int add = (endSize - oldSize) * value; int size = oldSize + add; KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setIconSize(size); q->scheduleDelayedItemsLayout(); } void KFilePlacesView::Private::_k_itemAppearUpdate(qreal value) { KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setAppearingItemProgress(value); q->scheduleDelayedItemsLayout(); } void KFilePlacesView::Private::_k_itemDisappearUpdate(qreal value) { KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setDisappearingItemProgress(value); if (value >= 1.0) { updateHiddenRows(); } q->scheduleDelayedItemsLayout(); } void KFilePlacesView::Private::_k_enableSmoothItemResizing() { smoothItemResizing = true; } void KFilePlacesView::Private::_k_capacityBarFadeValueChanged() { const QModelIndex index = delegate->indexForFadeAnimation(static_cast(q->sender())); if (!index.isValid()) { return; } q->update(index); } void KFilePlacesView::Private::_k_triggerDevicePolling() { const QModelIndex hoveredIndex = watcher->hoveredIndex(); if (hoveredIndex.isValid()) { const KFilePlacesModel *placesModel = static_cast(hoveredIndex.model()); if (placesModel->isDevice(hoveredIndex)) { q->update(hoveredIndex); } } const QModelIndex focusedIndex = watcher->focusedIndex(); if (focusedIndex.isValid() && focusedIndex != hoveredIndex) { const KFilePlacesModel *placesModel = static_cast(focusedIndex.model()); if (placesModel->isDevice(focusedIndex)) { q->update(focusedIndex); } } } void KFilePlacesView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { QListView::dataChanged(topLeft, bottomRight, roles); d->adaptItemSize(); } #include "moc_kfileplacesview.cpp" #include "moc_kfileplacesview_p.cpp" #include "kfileplacesview.moc" diff --git a/src/filewidgets/kfileplacesview.h b/src/filewidgets/kfileplacesview.h index a467bebd..b68c8e2b 100644 --- a/src/filewidgets/kfileplacesview.h +++ b/src/filewidgets/kfileplacesview.h @@ -1,117 +1,117 @@ /* This file is part of the KDE project Copyright (C) 2007 Kevin Ottens This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KFILEPLACESVIEW_H #define KFILEPLACESVIEW_H #include "kiofilewidgets_export.h" #include #include class QResizeEvent; class QContextMenuEvent; /** * @class KFilePlacesView kfileplacesview.h * * This class allows to display a KFilePlacesModel. */ class KIOFILEWIDGETS_EXPORT KFilePlacesView : public QListView { Q_OBJECT public: - KFilePlacesView(QWidget *parent = nullptr); - ~KFilePlacesView(); + explicit KFilePlacesView(QWidget *parent = nullptr); + ~KFilePlacesView() Q_DECL_OVERRIDE; /** * If \a enabled is true, it is allowed dropping items * above a place for e. g. copy or move operations. The application * has to take care itself to perform the operation * (see KFilePlacesView::urlsDropped()). If * \a enabled is false, it is only possible adding items * as additional place. Per default dropping on a place is * disabled. */ void setDropOnPlaceEnabled(bool enabled); bool isDropOnPlaceEnabled() const; /** * If \a enabled is true (the default), items will automatically resize * themselves to fill the view. * * @since 4.1 */ void setAutoResizeItemsEnabled(bool enabled); bool isAutoResizeItemsEnabled() const; public Q_SLOTS: void setUrl(const QUrl &url); void setShowAll(bool showAll); QSize sizeHint() const Q_DECL_OVERRIDE; void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE; protected: void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE; void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE; void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE; void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; void startDrag(Qt::DropActions supportedActions) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; protected Q_SLOTS: void rowsInserted(const QModelIndex &parent, int start, int end) Q_DECL_OVERRIDE; void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) Q_DECL_OVERRIDE; Q_SIGNALS: void urlChanged(const QUrl &url); /** * Is emitted if items are dropped on the place \a dest. * The application has to take care itself about performing the * corresponding action like copying or moving. */ void urlsDropped(const QUrl &dest, QDropEvent *event, QWidget *parent); private: Q_PRIVATE_SLOT(d, void adaptItemSize()) Q_PRIVATE_SLOT(d, void _k_placeClicked(const QModelIndex &)) Q_PRIVATE_SLOT(d, void _k_placeEntered(const QModelIndex &)) Q_PRIVATE_SLOT(d, void _k_placeLeft(const QModelIndex &)) Q_PRIVATE_SLOT(d, void _k_storageSetupDone(const QModelIndex &, bool)) Q_PRIVATE_SLOT(d, void _k_adaptItemsUpdate(qreal)) Q_PRIVATE_SLOT(d, void _k_itemAppearUpdate(qreal)) Q_PRIVATE_SLOT(d, void _k_itemDisappearUpdate(qreal)) Q_PRIVATE_SLOT(d, void _k_enableSmoothItemResizing()) Q_PRIVATE_SLOT(d, void _k_capacityBarFadeValueChanged()) Q_PRIVATE_SLOT(d, void _k_triggerDevicePolling()) class Private; Private *const d; friend class Private; }; #endif diff --git a/src/filewidgets/kfilewidget.h b/src/filewidgets/kfilewidget.h index 216e5b3e..efef3aad 100644 --- a/src/filewidgets/kfilewidget.h +++ b/src/filewidgets/kfilewidget.h @@ -1,617 +1,617 @@ // -*- c++ -*- /* This file is part of the KDE libraries Copyright (C) 1997, 1998 Richard Moore 1998 Stephan Kulow 1998 Daniel Grana 2000,2001 Carsten Pfeiffer 2001 Frerich Raabe 2007 David Faure 2008 Rafael Fernández López This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KFILEWIDGET_H #define KFILEWIDGET_H #include "kiofilewidgets_export.h" #include "kfile.h" #include class QUrl; class QPushButton; class KActionCollection; class KToolBar; class KFileWidgetPrivate; class KUrlComboBox; class KFileFilterCombo; class KPreviewWidgetBase; class QMimeType; class KConfigGroup; class KJob; class KFileItem; class KDirOperator; /** * @class KFileWidget kfilewidget.h * * File selector widget. * * This is the contents of the KDE file dialog, without the actual QDialog around it. * It can be embedded directly into applications. */ class KIOFILEWIDGETS_EXPORT KFileWidget : public QWidget { Q_OBJECT public: /** * Constructs a file selector widget. * * @param startDir This can either be: * @li An empty URL (QUrl()) to start in the current working directory, * or the last directory where a file has been selected. * @li The path or URL of a starting directory. * @li An initial file name to select, with the starting directory being * the current working directory or the last directory where a file * has been selected. * @li The path or URL of a file, specifying both the starting directory and * an initially selected file name. * @li A URL of the form @c kfiledialog:///<keyword> to start in the * directory last used by a filedialog in the same application that * specified the same keyword. * @li A URL of the form @c kfiledialog:///<keyword>/<filename> * to start in the directory last used by a filedialog in the same * application that specified the same keyword, and to initially * select the specified filename. * @li A URL of the form @c kfiledialog:///<keyword>?global to start * in the directory last used by a filedialog in any application that * specified the same keyword. * @li A URL of the form @c kfiledialog:///<keyword>/<filename>?global * to start in the directory last used by a filedialog in any * application that specified the same keyword, and to initially * select the specified filename. * * @param parent The parent widget of this widget * */ explicit KFileWidget(const QUrl &startDir, QWidget *parent = nullptr); /** * Destructor */ - virtual ~KFileWidget(); + ~KFileWidget() Q_DECL_OVERRIDE; /** * Defines some default behavior of the filedialog. * E.g. in mode @p Opening and @p Saving, the selected files/urls will * be added to the "recent documents" list. The Saving mode also implies * setKeepLocation() being set. * * @p Other means that no default actions are performed. * * @see setOperationMode * @see operationMode */ enum OperationMode { Other = 0, Opening, Saving }; /** * @returns The selected fully qualified filename. */ QUrl selectedUrl() const; /** * @returns The list of selected URLs. */ QList selectedUrls() const; /** * @returns the currently shown directory. */ QUrl baseUrl() const; /** * Returns the full path of the selected file in the local filesystem. * (Local files only) */ QString selectedFile() const; /** * Returns a list of all selected local files. */ QStringList selectedFiles() const; /** * Sets the directory to view. * * @param url URL to show. * @param clearforward Indicates whether the forward queue * should be cleared. */ void setUrl(const QUrl &url, bool clearforward = true); #if !defined(KIOFILEWIDGETS_NO_DEPRECATED) && !defined(DOXYGEN_SHOULD_SKIP_THIS) /** * Sets the file to preselect to @p pathOrUrl * * This method handles absolute paths (on Unix, but probably not correctly on Windows) * and absolute URLs as strings (but for those you should use setSelectedUrl instead). * * This method does not work with relative paths (filenames) * (it would misinterpret a ':' or a '#' in the filename). * * @deprecated since 5.33, use setSelectedUrl instead, after ensuring that * construct the QUrl correctly (e.g. use fromLocalFile for local paths). */ KIOFILEWIDGETS_DEPRECATED void setSelection(const QString &pathOrUrl); #endif /** * Sets the URL to preselect to @p url * * This method handles absolute URLs (remember to use fromLocalFile for local paths). * It also handles relative URLs, which you should construct like this: * QUrl relativeUrl; relativeUrl.setPath(fileName); * * @since 5.33 */ void setSelectedUrl(const QUrl &url); /** * Sets the operational mode of the filedialog to @p Saving, @p Opening * or @p Other. This will set some flags that are specific to loading * or saving files. E.g. setKeepLocation() makes mostly sense for * a save-as dialog. So setOperationMode( KFileWidget::Saving ); sets * setKeepLocation for example. * * The mode @p Saving, together with a default filter set via * setMimeFilter() will make the filter combobox read-only. * * The default mode is @p Opening. * * Call this method right after instantiating KFileWidget. * * @see operationMode * @see KFileWidget::OperationMode */ void setOperationMode(OperationMode); /** * @returns the current operation mode, Opening, Saving or Other. Default * is Other. * * @see operationMode * @see KFileWidget::OperationMode */ OperationMode operationMode() const; /** * Sets whether the filename/url should be kept when changing directories. * This is for example useful when having a predefined filename where * the full path for that file is searched. * * This is implicitly set when operationMode() is KFileWidget::Saving * * getSaveFileName() and getSaveUrl() set this to true by default, so that * you can type in the filename and change the directory without having * to type the name again. */ void setKeepLocation(bool keep); /** * @returns whether the contents of the location edit are kept when * changing directories. */ bool keepsLocation() const; /** * Sets the filter to be used to @p filter. * * You can set more * filters for the user to select separated by '\n'. Every * filter entry is defined through namefilter|text to display. * If no | is found in the expression, just the namefilter is * shown. Examples: * * \code * kfile->setFilter("*.cpp|C++ Source Files\n*.h|Header files"); * kfile->setFilter("*.cpp"); * kfile->setFilter("*.cpp|Sources (*.cpp)"); * kfile->setFilter("*.cpp|" + i18n("Sources (*.cpp)")); * kfile->setFilter("*.cpp *.cc *.C|C++ Source Files\n*.h *.H|Header files"); * \endcode * * Note: The text to display is not parsed in any way. So, if you * want to show the suffix to select by a specific filter, you must * repeat it. * * If the filter contains an unescaped '/', a mimetype-filter is assumed. * If you would like a '/' visible in your filter it can be escaped with * a '\'. You can specify multiple mimetypes like this (separated with * space): * * \code * kfile->setFilter( "image/png text/html text/plain" ); * kfile->setFilter( "*.cue|CUE\\/BIN Files (*.cue)" ); * \endcode * * @see filterChanged * @see setMimeFilter */ void setFilter(const QString &filter); /** * Returns the current filter as entered by the user or one of the * predefined set via setFilter(). * * @see setFilter() * @see filterChanged() */ QString currentFilter() const; /** * Returns the mimetype for the desired output format. * * This is only valid if setFilterMimeType() has been called * previously. * * @see setFilterMimeType() */ QMimeType currentFilterMimeType(); /** * Sets the filter up to specify the output type. * * @param types a list of mimetypes that can be used as output format * @param defaultType the default mimetype to use as output format, if any. * If @p defaultType is set, it will be set as the current item. * Otherwise, a first item showing all the mimetypes will be created. * Typically, @p defaultType should be empty for loading and set for saving. * * Do not use in conjunction with setFilter() */ void setMimeFilter(const QStringList &types, const QString &defaultType = QString()); /** * The mimetype for the desired output format. * * This is only valid if setMimeFilter() has been called * previously. * * @see setMimeFilter() */ QString currentMimeFilter() const; /** * Clears any mime- or namefilter. Does not reload the directory. */ void clearFilter(); /** * Adds a preview widget and enters the preview mode. * * In this mode the dialog is split and the right part contains your * preview widget. * * Ownership is transferred to KFileWidget. You need to create the * preview-widget with "new", i.e. on the heap. * * @param w The widget to be used for the preview. */ void setPreviewWidget(KPreviewWidgetBase *w); /** * Sets the mode of the dialog. * * The mode is defined as (in kfile.h): * \code * enum Mode { * File = 1, * Directory = 2, * Files = 4, * ExistingOnly = 8, * LocalOnly = 16 * }; * \endcode * You can OR the values, e.g. * \code * KFile::Modes mode = KFile::Files | * KFile::ExistingOnly | * KFile::LocalOnly ); * setMode( mode ); * \endcode */ void setMode(KFile::Modes m); /** * Returns the mode of the filedialog. * @see setMode() */ KFile::Modes mode() const; /** * Sets the text to be displayed in front of the selection. * * The default is "Location". * Most useful if you want to make clear what * the location is used for. */ void setLocationLabel(const QString &text); /** * Returns a pointer to the toolbar. * */ KToolBar *toolBar() const; /** * @returns a pointer to the OK-Button in the filedialog. * Note that the button is hidden and unconnected when using KFileWidget alone; * KFileDialog shows it and connects to it. */ QPushButton *okButton() const; /** * @returns a pointer to the Cancel-Button in the filedialog. * Note that the button is hidden and unconnected when using KFileWidget alone; * KFileDialog shows it and connects to it. */ QPushButton *cancelButton() const; /** * @returns the combobox used to type the filename or full location of the file. */ KUrlComboBox *locationEdit() const; /** * @returns the combobox that contains the filters */ KFileFilterCombo *filterWidget() const; /** * @returns a pointer to the action collection, holding all the used * KActions. */ KActionCollection *actionCollection() const; /** * This method implements the logic to determine the user's default directory * to be listed. E.g. the documents directory, home directory or a recently * used directory. * @param startDir A URL specifying the initial directory, or using the * @c kfiledialog:/// syntax to specify a last used * directory. If this URL specifies a file name, it is * ignored. Refer to the KFileWidget::KFileWidget() * documentation for the @c kfiledialog:/// URL syntax. * @param recentDirClass If the @c kfiledialog:/// syntax is used, this * will return the string to be passed to KRecentDirs::dir() and * KRecentDirs::add(). * @return The URL that should be listed by default (e.g. by KFileDialog or * KDirSelectDialog). * @see KFileWidget::KFileWidget() */ static QUrl getStartUrl(const QUrl &startDir, QString &recentDirClass); /** * Similar to getStartUrl(const QUrl& startDir,QString& recentDirClass), * but allows both the recent start directory keyword and a suggested file name * to be returned. * @param startDir A URL specifying the initial directory and/or filename, * or using the @c kfiledialog:/// syntax to specify a * last used location. * Refer to the KFileWidget::KFileWidget() * documentation for the @c kfiledialog:/// URL syntax. * @param recentDirClass If the @c kfiledialog:/// syntax is used, this * will return the string to be passed to KRecentDirs::dir() and * KRecentDirs::add(). * @param fileName The suggested file name, if specified as part of the * @p StartDir URL. * @return The URL that should be listed by default (e.g. by KFileDialog or * KDirSelectDialog). * * @see KFileWidget::KFileWidget() * @since 4.3 */ static QUrl getStartUrl(const QUrl &startDir, QString &recentDirClass, QString &fileName); /** * @internal * Used by KDirSelectDialog to share the dialog's start directory. */ static void setStartDir(const QUrl &directory); /** * Set a custom widget that should be added to the file dialog. * @param widget A widget, or a widget of widgets, for displaying custom * data in the file widget. This can be used, for example, to * display a check box with the caption "Open as read-only". * When creating this widget, you don't need to specify a parent, * since the widget's parent will be set automatically by KFileWidget. */ void setCustomWidget(QWidget *widget); /** * Sets a custom widget that should be added below the location and the filter * editors. * @param text Label of the custom widget, which is displayed below the labels * "Location:" and "Filter:". * @param widget Any kind of widget, but preferable a combo box or a line editor * to be compliant with the location and filter layout. * When creating this widget, you don't need to specify a parent, * since the widget's parent will be set automatically by KFileWidget. */ void setCustomWidget(const QString &text, QWidget *widget); /** * Sets whether the user should be asked for confirmation * when an overwrite might occurr. * * @param enable Set this to true to enable checking. * @since 4.2 */ void setConfirmOverwrite(bool enable); /** * Forces the inline previews to be shown or hidden, depending on @p show. * * @param show Whether to show inline previews or not. * @since 4.2 */ void setInlinePreviewShown(bool show); /** * Provides a size hint, useful for dialogs that embed the widget. * * @return a QSize, calculated to be optimal for a dialog. * @since 5.0 */ QSize dialogSizeHint() const; /** * Sets how the view should be displayed. * * @see KFile::FileView * @since 5.0 */ void setViewMode(KFile::FileView mode); /** * Reimplemented */ QSize sizeHint() const Q_DECL_OVERRIDE; /** * Set the URL schemes that the file widget should allow navigating to. * * If the returned list is empty, all schemes are supported. * * @sa QFileDialog::setSupportedSchemes * @since 5.43 */ void setSupportedSchemes(const QStringList &schemes); /** * Returns the URL schemes that the file widget should allow navigating to. * * If the returned list is empty, all schemes are supported. Examples for * schemes are @c "file" or @c "ftp". * * @sa QFileDialog::supportedSchemes * @since 5.43 */ QStringList supportedSchemes() const; public Q_SLOTS: /** * Called when clicking ok (when this widget is used in KFileDialog) * Might or might not call accept(). */ void slotOk(); void accept(); void slotCancel(); protected: void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; Q_SIGNALS: /** * Emitted when the user selects a file. It is only emitted in single- * selection mode. The best way to get notified about selected file(s) * is to connect to the okClicked() signal inherited from KDialog * and call selectedFile(), selectedFiles(), * selectedUrl() or selectedUrls(). * * \since 4.4 */ void fileSelected(const QUrl &); /** * Emitted when the user highlights a file. * \since 4.4 */ void fileHighlighted(const QUrl &); /** * Emitted when the user hilights one or more files in multiselection mode. * * Note: fileHighlighted() or fileSelected() are @em not * emitted in multiselection mode. You may use selectedItems() to * ask for the current highlighted items. * @see fileSelected */ void selectionChanged(); /** * Emitted when the filter changed, i.e. the user entered an own filter * or chose one of the predefined set via setFilter(). * * @param filter contains the new filter (only the extension part, * not the explanation), i.e. "*.cpp" or "*.cpp *.cc". * * @see setFilter() * @see currentFilter() */ void filterChanged(const QString &filter); /** * Emitted by slotOk() (directly or asynchronously) once everything has * been done. Should be used by the caller to call accept(). */ void accepted(); public: /** * @returns the KDirOperator used to navigate the filesystem * @since 4.3 */ KDirOperator *dirOperator(); /** * reads the configuration for this widget from the given config group * @param group the KConfigGroup to read from * @since 4.4 */ void readConfig(KConfigGroup &group); private: friend class KFileWidgetPrivate; KFileWidgetPrivate *const d; Q_PRIVATE_SLOT(d, void _k_slotLocationChanged(const QString &)) Q_PRIVATE_SLOT(d, void _k_urlEntered(const QUrl &)) Q_PRIVATE_SLOT(d, void _k_enterUrl(const QUrl &)) Q_PRIVATE_SLOT(d, void _k_enterUrl(const QString &)) Q_PRIVATE_SLOT(d, void _k_locationAccepted(const QString &)) Q_PRIVATE_SLOT(d, void _k_slotFilterChanged()) Q_PRIVATE_SLOT(d, void _k_fileHighlighted(const KFileItem &)) Q_PRIVATE_SLOT(d, void _k_fileSelected(const KFileItem &)) Q_PRIVATE_SLOT(d, void _k_slotLoadingFinished()) Q_PRIVATE_SLOT(d, void _k_fileCompletion(const QString &)) Q_PRIVATE_SLOT(d, void _k_toggleSpeedbar(bool)) Q_PRIVATE_SLOT(d, void _k_toggleBookmarks(bool)) Q_PRIVATE_SLOT(d, void _k_slotAutoSelectExtClicked()) Q_PRIVATE_SLOT(d, void _k_placesViewSplitterMoved(int, int)) Q_PRIVATE_SLOT(d, void _k_activateUrlNavigator()) Q_PRIVATE_SLOT(d, void _k_zoomOutIconsSize()) Q_PRIVATE_SLOT(d, void _k_zoomInIconsSize()) Q_PRIVATE_SLOT(d, void _k_slotIconSizeSliderMoved(int)) Q_PRIVATE_SLOT(d, void _k_slotIconSizeChanged(int)) }; #endif diff --git a/src/filewidgets/kimagefilepreview.h b/src/filewidgets/kimagefilepreview.h index 6e8bd95e..eec13fb0 100644 --- a/src/filewidgets/kimagefilepreview.h +++ b/src/filewidgets/kimagefilepreview.h @@ -1,86 +1,86 @@ /* * * This file is part of the KDE project. * Copyright (C) 2001 Martin R. Jones * 2001 Carsten Pfeiffer * 2008 Rafael Fernández López * * You can Freely distribute this program under the GNU Library General Public * License. See the file "COPYING" for the exact licensing terms. */ #ifndef KIMAGEFILEPREVIEW_H #define KIMAGEFILEPREVIEW_H #include #include #include class KFileItem; class KJob; namespace KIO { class PreviewJob; } /** * @class KImageFilePreview kimagefilepreview.h * * Image preview widget for the file dialog. */ class KIOFILEWIDGETS_EXPORT KImageFilePreview : public KPreviewWidgetBase { Q_OBJECT public: /** * Creates a new image file preview. * * @param parent The parent widget. */ explicit KImageFilePreview(QWidget *parent = nullptr); /** * Destroys the image file preview. */ - ~KImageFilePreview(); + ~KImageFilePreview() Q_DECL_OVERRIDE; /** * Returns the size hint for this widget. */ QSize sizeHint() const Q_DECL_OVERRIDE; public Q_SLOTS: /** * Shows a preview for the given @p url. */ void showPreview(const QUrl &url) Q_DECL_OVERRIDE; /** * Clears the preview. */ void clearPreview() Q_DECL_OVERRIDE; protected Q_SLOTS: void showPreview(); void showPreview(const QUrl &url, bool force); virtual void gotPreview(const KFileItem &, const QPixmap &); protected: void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; virtual KIO::PreviewJob *createJob(const QUrl &url, int width, int height); private: class KImageFilePreviewPrivate; KImageFilePreviewPrivate *const d; Q_DISABLE_COPY(KImageFilePreview) Q_PRIVATE_SLOT(d, void _k_slotResult(KJob *)) Q_PRIVATE_SLOT(d, void _k_slotFailed(const KFileItem &)) Q_PRIVATE_SLOT(d, void _k_slotStepAnimation(int frame)) Q_PRIVATE_SLOT(d, void _k_slotFinished()) }; #endif // KIMAGEFILEPREVIEW_H diff --git a/src/filewidgets/kpreviewwidgetbase.h b/src/filewidgets/kpreviewwidgetbase.h index 029e9993..08cf94de 100644 --- a/src/filewidgets/kpreviewwidgetbase.h +++ b/src/filewidgets/kpreviewwidgetbase.h @@ -1,88 +1,88 @@ /* This file is part of the KDE libraries * Copyright (C) 2001 Frerich Raabe * 2003 Carsten Pfeiffer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef __KPREVIEWWIDGETBASE_H__ #define __KPREVIEWWIDGETBASE_H__ #include #include "kiofilewidgets_export.h" class QUrl; /** * @class KPreviewWidgetBase kpreviewwidgetbase.h * * Abstract baseclass for all preview widgets which shall be used via * KFileDialog::setPreviewWidget(const KPreviewWidgetBase *). * Ownership will be transferred to KFileDialog, so you have to create * the preview with "new" and let KFileDialog delete it. * * Just derive your custom preview widget from KPreviewWidgetBase and implement * all the pure virtual methods. The slot showPreview(const QUrl &) is called * every time the file selection changes. * * @short Abstract baseclass for all preview widgets. * @author Frerich Raabe */ class KIOFILEWIDGETS_EXPORT KPreviewWidgetBase : public QWidget { Q_OBJECT public: /** * Constructor. Construct the user interface of your preview widget here * and pass the KFileDialog this preview widget is going to be used in as * the parent. * * @param parent The KFileDialog this preview widget is going to be used in */ - KPreviewWidgetBase(QWidget *parent); + explicit KPreviewWidgetBase(QWidget *parent); ~KPreviewWidgetBase(); public Q_SLOTS: /** * This slot is called every time the user selects another file in the * file dialog. Implement the stuff necessary to reflect the change here. * * @param url The URL of the currently selected file. */ virtual void showPreview(const QUrl &url) = 0; /** * Reimplement this to clear the preview. This is called when e.g. the * selection is cleared or when multiple selections exist, or the directory * is changed. */ virtual void clearPreview() = 0; QStringList supportedMimeTypes() const; protected: void setSupportedMimeTypes(const QStringList &mimeTypes); private: class KPreviewWidgetBasePrivate; KPreviewWidgetBasePrivate *const d; Q_DISABLE_COPY(KPreviewWidgetBase) }; #endif diff --git a/src/filewidgets/kurlnavigatordropdownbutton_p.h b/src/filewidgets/kurlnavigatordropdownbutton_p.h index 8d7f11ab..096ac3bd 100644 --- a/src/filewidgets/kurlnavigatordropdownbutton_p.h +++ b/src/filewidgets/kurlnavigatordropdownbutton_p.h @@ -1,53 +1,53 @@ /***************************************************************************** * Copyright (C) 2006 by Peter Penz * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #ifndef KURLNAVIGATORDROPDOWNBUTTON_P_H #define KURLNAVIGATORDROPDOWNBUTTON_P_H #include "kurlnavigatorbuttonbase_p.h" namespace KDEPrivate { /** * @brief Button of the URL navigator which offers a drop down menu * of hidden paths. * * The button will only be shown if the width of the URL navigator is * too small to show the whole path. */ class KUrlNavigatorDropDownButton : public KUrlNavigatorButtonBase { Q_OBJECT public: explicit KUrlNavigatorDropDownButton(QWidget *parent); - virtual ~KUrlNavigatorDropDownButton(); + ~KUrlNavigatorDropDownButton() Q_DECL_OVERRIDE; /** @see QWidget::sizeHint() */ QSize sizeHint() const Q_DECL_OVERRIDE; protected: void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; }; } // namespace KDEPrivate #endif diff --git a/src/filewidgets/kurlnavigatormenu_p.h b/src/filewidgets/kurlnavigatormenu_p.h index d9319099..35309a60 100644 --- a/src/filewidgets/kurlnavigatormenu_p.h +++ b/src/filewidgets/kurlnavigatormenu_p.h @@ -1,69 +1,69 @@ /* Copyright (C) 2009 by Rahman Duran This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KURLNAVIGATORMENU_P_H #define KURLNAVIGATORMENU_P_H #include namespace KDEPrivate { /** * @brief Provides drop-down menus for the URL navigator. * * The implementation extends KMenu with drag & drop support. * * @internal */ class KUrlNavigatorMenu : public QMenu { Q_OBJECT public: explicit KUrlNavigatorMenu(QWidget *parent); - virtual ~KUrlNavigatorMenu(); + ~KUrlNavigatorMenu() Q_DECL_OVERRIDE; Q_SIGNALS: /** * Is emitted when drop event occurs. */ void urlsDropped(QAction *action, QDropEvent *event); /** * Is emitted, if the action \p action has been clicked. */ void mouseButtonClicked(QAction *action, Qt::MouseButton button); protected: void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE; void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; private: const QPoint m_initialMousePosition; bool m_mouseMoved; }; } // namespace KDEPrivate #endif diff --git a/src/filewidgets/kurlnavigatorplacesselector_p.h b/src/filewidgets/kurlnavigatorplacesselector_p.h index 8b518a9c..99f4052a 100644 --- a/src/filewidgets/kurlnavigatorplacesselector_p.h +++ b/src/filewidgets/kurlnavigatorplacesselector_p.h @@ -1,123 +1,123 @@ /*************************************************************************** * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) * * Copyright (C) 2007 by Kevin Ottens (ervin@kde.org) * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef KURLNAVIGATORPLACESSELECTOR_P_H #define KURLNAVIGATORPLACESSELECTOR_P_H #include "kurlnavigatorbuttonbase_p.h" #include #include class KFilePlacesModel; class QMenu; namespace KDEPrivate { /** * @brief Allows to select a bookmark from a popup menu. * * The icon from the current selected bookmark is shown * inside the bookmark selector. * * @see KUrlNavigator * @internal */ class KUrlNavigatorPlacesSelector : public KUrlNavigatorButtonBase { Q_OBJECT public: /** * @param parent Parent widget where the bookmark selector * is embedded into. */ KUrlNavigatorPlacesSelector(QWidget *parent, KFilePlacesModel *placesModel); - virtual ~KUrlNavigatorPlacesSelector(); + ~KUrlNavigatorPlacesSelector() Q_DECL_OVERRIDE; /** * Updates the selection dependent from the given URL \a url. The * URL must not match exactly to one of the available bookmarks: * The bookmark which is equal to the URL or at least is a parent URL * is selected. If there are more than one possible parent URL candidates, * the bookmark which covers the bigger range of the URL is selected. */ void updateSelection(const QUrl &url); /** Returns the selected bookmark. */ QUrl selectedPlaceUrl() const; /** Returns the selected bookmark. */ QString selectedPlaceText() const; /** @see QWidget::sizeHint() */ QSize sizeHint() const Q_DECL_OVERRIDE; Q_SIGNALS: /** * Is send when a bookmark has been activated by the user. * @param url URL of the selected place. */ void placeActivated(const QUrl &url); /** * Is sent when a bookmark was middle clicked by the user * and thus should be opened in a new tab. */ void tabRequested(const QUrl &url); protected: /** * Draws the icon of the selected Url as content of the Url * selector. */ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE; void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *event) override; bool eventFilter(QObject *watched, QEvent *event) override; private Q_SLOTS: /** * Updates the selected index and the icon to the bookmark * which is indicated by the triggered action \a action. */ void activatePlace(QAction *action); void updateMenu(); void updateTeardownAction(); void onStorageSetupDone(const QModelIndex &index, bool success); private: int m_selectedItem; QPersistentModelIndex m_lastClickedIndex; QMenu *m_placesMenu; KFilePlacesModel *m_placesModel; QUrl m_selectedUrl; }; } // namespace KDEPrivate #endif diff --git a/src/filewidgets/kurlnavigatortogglebutton_p.h b/src/filewidgets/kurlnavigatortogglebutton_p.h index 1b258ab7..6559f787 100644 --- a/src/filewidgets/kurlnavigatortogglebutton_p.h +++ b/src/filewidgets/kurlnavigatortogglebutton_p.h @@ -1,61 +1,61 @@ /***************************************************************************** * Copyright (C) 2006 by Peter Penz * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public License * * along with this library; see the file COPYING.LIB. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #ifndef KURLNAVIGATORTOGGLEBUTTON_P_H #define KURLNAVIGATORTOGGLEBUTTON_P_H #include "kurlnavigatorbuttonbase_p.h" #include namespace KDEPrivate { /** * @brief Represents the button of the URL navigator to switch to * the editable mode. * * A cursor is shown when hovering the button. */ class KUrlNavigatorToggleButton : public KUrlNavigatorButtonBase { Q_OBJECT public: explicit KUrlNavigatorToggleButton(QWidget *parent); - virtual ~KUrlNavigatorToggleButton(); + ~KUrlNavigatorToggleButton() Q_DECL_OVERRIDE; /** @see QWidget::sizeHint() */ QSize sizeHint() const Q_DECL_OVERRIDE; protected: void enterEvent(QEvent *event) Q_DECL_OVERRIDE; void leaveEvent(QEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; private Q_SLOTS: void updateToolTip(); void updateCursor(); private: QPixmap m_pixmap; }; } // namespace KDEPrivate #endif