File indexing completed on 2024-04-21 15:55:47
0001 /************************************************************************** 0002 * Copyright (C) 2008-2019 by Michel Ludwig (michel.ludwig@kdemail.net) * 0003 ***************************************************************************/ 0004 0005 /************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 ***************************************************************************/ 0013 0014 #ifndef UTILITIES_H 0015 #define UTILITIES_H 0016 0017 #include <QAction> 0018 #include <QStandardPaths> 0019 #include <KService> 0020 #include <QUrl> 0021 0022 class ServiceRunAction : public QAction { 0023 Q_OBJECT 0024 0025 public: 0026 ServiceRunAction(const KService& service, 0027 const QList<QUrl>& urls, 0028 QWidget* window, 0029 bool tempFiles = false, 0030 const QString& suggestedFileName = QString(), 0031 const QByteArray& asn = "", 0032 QObject *parent = Q_NULLPTR); 0033 ~ServiceRunAction(); 0034 0035 protected Q_SLOTS: 0036 void runService(); 0037 0038 protected: 0039 const KService& m_service; 0040 QList<QUrl> m_urlList; 0041 QWidget* m_window; 0042 bool m_tempFiles; 0043 QString m_suggestedFileName; 0044 QByteArray m_asn; 0045 }; 0046 0047 namespace KileUtilities { 0048 0049 /** 0050 * @brief Finds the file with the most recent modification time from a list 0051 * 0052 * Checks last modification time for files and returns absolute (see @ref baseDir description) file name of 0053 * file with the latest modification time 0054 * @param files List of filenames, relative to @ref baseDir 0055 * @param baseDir Path to base directory. If empty, @ref files are used as they are 0056 * @return Absolute path of the file with the latest modification time or empty string if @ref files is empty 0057 **/ 0058 QString lastModifiedFile(const QStringList& files, const QString& baseDir = QString()); 0059 0060 0061 /** 0062 * Centers the given widget w.r.t. its parent. If it doesn't have a parent, the containing screen is used. 0063 **/ 0064 void centerWidgetRelativeToParent(QWidget *widget); 0065 0066 /** 0067 * Schedules the centering of the given widget w.r.t. its parent in the event loop. 0068 **/ 0069 void scheduleCenteringOfWidget(QWidget *widget); 0070 0071 /** 0072 * If 'url' is a local file, the canonical file path is returned if the file exists. Otherwise, 0073 * the cleaned file path is returned (see QDir::cleanPath). 0074 * If 'url' is not a local file, 'url' is returned. 0075 **/ 0076 QUrl canonicalUrl(const QUrl &url); 0077 0078 0079 /** 0080 * Add our own versions of most QStandardPaths:: methods, which allow to locate 'DataLocation' or 0081 * 'AppDataLocation' items under <app binary dir>/../share/kile 0082 * This is necessary for being able to create an AppImage 0083 **/ 0084 0085 QString findExecutable(const QString &executableName, const QStringList &paths = QStringList()); 0086 0087 QString locate(QStandardPaths::StandardLocation type, 0088 const QString &fileName, 0089 QStandardPaths::LocateOptions options = QStandardPaths::LocateFile); 0090 0091 QStringList locateAll(QStandardPaths::StandardLocation type, 0092 const QString &fileName, 0093 QStandardPaths::LocateOptions options = QStandardPaths::LocateFile); 0094 0095 QStringList standardLocations(QStandardPaths::StandardLocation type); 0096 0097 QString writableLocation(QStandardPaths::StandardLocation type); 0098 } 0099 0100 #endif