File indexing completed on 2024-05-19 04:56:07
0001 /** 0002 * \file scriptinterface.h 0003 * D-Bus script adaptor. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 20 Dec 2007 0008 * 0009 * Copyright (C) 2007-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include "config.h" 0030 #ifdef HAVE_QTDBUS 0031 #include <QDBusAbstractAdaptor> 0032 #include <QStringList> 0033 0034 class Kid3Application; 0035 0036 /** 0037 * Adaptor class for interface org.kde.Kid3 0038 * Create org.kde.Kid3.xml with: 0039 * echo "#define HAVE_QTDBUS" >config.h 0040 * qdbuscpp2xml scriptinterface.h >org.kde.Kid3.xml 0041 * rm config.h 0042 */ 0043 class ScriptInterface : public QDBusAbstractAdaptor { 0044 Q_OBJECT 0045 Q_CLASSINFO("D-Bus Interface", "org.kde.Kid3") 0046 public: 0047 /** 0048 * Constructor. 0049 * 0050 * @param app parent application 0051 */ 0052 explicit ScriptInterface(Kid3Application* app); 0053 0054 /** 0055 * Destructor. 0056 */ 0057 ~ScriptInterface() override = default; 0058 0059 public slots: 0060 /** 0061 * Open file or directory. 0062 * 0063 * @param path path to file or directory 0064 * 0065 * @return true if ok. 0066 */ 0067 bool openDirectory(const QString& path); 0068 0069 /** 0070 * Unload all tags. 0071 * The tags of all files which are not modified or selected are freed to 0072 * reclaim their memory. 0073 */ 0074 void unloadAllTags(); 0075 0076 /** 0077 * Save all modified files. 0078 * 0079 * @return true if ok, 0080 * else the error message is available using getErrorMessage(). 0081 */ 0082 bool save(); 0083 0084 /** 0085 * Get a detailed error message provided by some methods. 0086 * @return detailed error message. 0087 */ 0088 QString getErrorMessage() const; // clazy:exclude=const-signal-or-slot 0089 0090 /** 0091 * Revert changes in the selected files. 0092 */ 0093 void revert(); 0094 0095 /** 0096 * Import tags from a file. 0097 * 0098 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0099 * @param path path of file, "clipboard" for import from clipboard 0100 * @param fmtIdx index of format 0101 * 0102 * @return true if ok. 0103 */ 0104 bool importFromFile(int tagMask, const QString& path, int fmtIdx); 0105 0106 /** 0107 * Import from tags. 0108 * 0109 * @param tagMask tag mask 0110 * @param source format to get source text from tags 0111 * @param extraction regular expression with frame names and captures to 0112 * extract from source text 0113 */ 0114 void importFromTags(int tagMask, 0115 const QString& source, const QString& extraction); 0116 0117 /** 0118 * Import from tags on selected files. 0119 * 0120 * @param tagMask tag mask 0121 * @param source format to get source text from tags 0122 * @param extraction regular expression with frame names and captures to 0123 * extract from source text 0124 * 0125 * @return extracted values for "%{__return}(.+)", empty if not used. 0126 */ 0127 QStringList importFromTagsToSelection(int tagMask, 0128 const QString& source, 0129 const QString& extraction); 0130 0131 /** 0132 * Start an automatic batch import. 0133 * 0134 * @param tagMask tag mask (bit 0 for tag 1, bit 1 for tag 2) 0135 * @param profileName name of batch import profile to use 0136 * 0137 * @return true if profile found. 0138 */ 0139 bool batchImport(int tagMask, const QString& profileName); 0140 0141 /** 0142 * Download album cover art into the picture frame of the selected files. 0143 * 0144 * @param url URL of picture file or album art resource 0145 * @param allFilesInDir true to add the image to all files in the directory 0146 */ 0147 void downloadAlbumArt(const QString& url, bool allFilesInDir); 0148 0149 /** 0150 * Export tags to a file. 0151 * 0152 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0153 * @param path path of file, "clipboard" for export to clipboard 0154 * @param fmtIdx index of format 0155 * 0156 * @return true if ok. 0157 */ 0158 bool exportToFile(int tagMask, const QString& path, int fmtIdx); 0159 0160 /** 0161 * Create a playlist. 0162 * 0163 * @return true if ok. 0164 */ 0165 bool createPlaylist(); 0166 0167 /** 0168 * Get items of a playlist. 0169 * @param path path to playlist file 0170 * @return list of absolute paths to playlist items. 0171 */ 0172 QStringList getPlaylistItems(const QString& path); 0173 0174 /** 0175 * Set items of a playlist. 0176 * 0177 * When using qdbus to call this function from the bash, the @a items have to 0178 * be enclosed in parentheses and the files must exist: 0179 * 0180 * @code 0181 * qdbus org.kde.kid3 /Kid3 setPlaylistItems "/path/to/playlist.m3u" 0182 * \( "/path/to/file1" "/path/to/file2" \) 0183 * @endcode 0184 * 0185 * @param path path to playlist file 0186 * @param items list of absolute paths to playlist items 0187 * @return true if ok, false if not all @a items were found and added or 0188 * saving failed. 0189 */ 0190 bool setPlaylistItems(const QString& path, const QStringList& items); 0191 0192 /** 0193 * Quit the application. 0194 * Omitted Q_NOREPLY because the Qt 3 moc chokes on it. 0195 */ 0196 void quit(); 0197 0198 /** 0199 * Select all files. 0200 */ 0201 void selectAll(); 0202 0203 /** 0204 * Deselect all files. 0205 */ 0206 void deselectAll(); 0207 0208 /** 0209 * Set the first file as the current file. 0210 * 0211 * @return true if there is a first file. 0212 */ 0213 bool firstFile(); 0214 0215 /** 0216 * Set the previous file as the current file. 0217 * 0218 * @return true if there is a previous file. 0219 */ 0220 bool previousFile(); 0221 0222 /** 0223 * Set the next file as the current file. 0224 * 0225 * @return true if there is a next file. 0226 */ 0227 bool nextFile(); 0228 0229 /** 0230 * Select the first file. 0231 * 0232 * @return true if there is a first file. 0233 */ 0234 bool selectFirstFile(); 0235 0236 /** 0237 * Select the previous file. 0238 * 0239 * @return true if there is a previous file. 0240 */ 0241 bool selectPreviousFile(); 0242 0243 /** 0244 * Select the next file. 0245 * 0246 * @return true if there is a next file. 0247 */ 0248 bool selectNextFile(); 0249 0250 /** 0251 * Select the current file. 0252 * 0253 * @return true if there is a current file. 0254 */ 0255 bool selectCurrentFile(); 0256 0257 /** 0258 * Expand or collapse the current file item if it is a directory. 0259 * A file list item is a directory if getFileName() returns a name with 0260 * '/' as the last character. 0261 * 0262 * @return true if current file item is a directory. 0263 */ 0264 bool expandDirectory(); 0265 0266 /** 0267 * Expand the file list. 0268 */ 0269 void expandFileList(); 0270 0271 /** 0272 * Apply the file name format. 0273 */ 0274 void applyFilenameFormat(); 0275 0276 /** 0277 * Apply the tag format. 0278 */ 0279 void applyTagFormat(); 0280 0281 /** 0282 * Apply text encoding. 0283 */ 0284 void applyTextEncoding(); 0285 0286 /** 0287 * Set the directory name from the tags. 0288 * 0289 * @param tagMask tag mask (bit 0 for tag 1, bit 1 for tag 2) 0290 * @param format directory name format 0291 * @param create true to create, false to rename 0292 * 0293 * @return true if ok, 0294 * else the error message is available using getErrorMessage(). 0295 */ 0296 bool setDirNameFromTag(int tagMask, const QString& format, bool create); 0297 0298 /** 0299 * Set subsequent track numbers in the selected files. 0300 * 0301 * @param tagMask tag mask (bit 0 for tag 1, bit 1 for tag 2) 0302 * @param firstTrackNr number to use for first file 0303 */ 0304 void numberTracks(int tagMask, int firstTrackNr); 0305 0306 /** 0307 * Filter the files. 0308 * 0309 * @param expression filter expression 0310 */ 0311 void filter(const QString& expression); 0312 0313 /** 0314 * Convert ID3v2.3 tags to ID3v2.4. 0315 */ 0316 void convertToId3v24(); 0317 0318 /** 0319 * Convert ID3v2.4 tags to ID3v2.3. 0320 */ 0321 void convertToId3v23(); 0322 0323 /** 0324 * Get path of directory. 0325 * 0326 * @return absolute path of directory. 0327 */ 0328 QString getDirectoryName(); 0329 0330 /** 0331 * Get name of current file. 0332 * 0333 * @return absolute file name, ends with "/" if it is a directory. 0334 */ 0335 QString getFileName(); 0336 0337 /** 0338 * Set name of selected file. 0339 * The file will be renamed when the directory is saved. 0340 * 0341 * @param name file name. 0342 */ 0343 void setFileName(const QString& name); 0344 0345 /** 0346 * Set format to use when setting the filename from the tags. 0347 * 0348 * @param format file name format 0349 * @see setFileNameFromTag() 0350 */ 0351 void setFileNameFormat(const QString& format); 0352 0353 /** 0354 * Set the file names of the selected files from the tags. 0355 * 0356 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0357 * @see setFileNameFormat() 0358 */ 0359 void setFileNameFromTag(int tagMask); 0360 0361 /** 0362 * Get value of frame. 0363 * To get binary data like a picture, the name of a file to write can be 0364 * added after the @a name, e.g. "Picture:/path/to/file". 0365 * 0366 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0367 * @param name name of frame (e.g. "artist") 0368 */ 0369 QString getFrame(int tagMask, const QString& name); 0370 0371 /** 0372 * Set value of frame. 0373 * For tag 2 (@a tagMask 2), if no frame with @a name exists, a new frame 0374 * is added, if @a value is empty, the frame is deleted. 0375 * To add binary data like a picture, a file can be added after the 0376 * @a name, e.g. "Picture:/path/to/file". 0377 * 0378 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0379 * @param name name of frame (e.g. "artist") 0380 * @param value value of frame 0381 */ 0382 bool setFrame(int tagMask, const QString& name, const QString& value); 0383 0384 /** 0385 * Get all frames of a tag. 0386 * 0387 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0388 * 0389 * @return list with alternating frame names and values. 0390 */ 0391 QStringList getTag(int tagMask); 0392 0393 /** 0394 * Get technical information about file. 0395 * Properties are Format, Bitrate, Samplerate, Channels, Duration, 0396 * Channel Mode, VBR, Tag 1, Tag 2. 0397 * Properties which are not available are omitted. 0398 * 0399 * @return list with alternating property names and values. 0400 */ 0401 QStringList getInformation(); 0402 0403 /** 0404 * Set tag from file name. 0405 * 0406 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0407 */ 0408 void setTagFromFileName(int tagMask); 0409 0410 /** 0411 * Set tag from other tag. 0412 * 0413 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0414 */ 0415 void setTagFromOtherTag(int tagMask); 0416 0417 /** 0418 * Copy tag. 0419 * 0420 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0421 */ 0422 void copyTag(int tagMask); 0423 0424 /** 0425 * Paste tag. 0426 * 0427 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0428 */ 0429 void pasteTag(int tagMask); 0430 0431 /** 0432 * Remove tag. 0433 * 0434 * @param tagMask tag bit (1 for tag 1, 2 for tag 2) 0435 */ 0436 void removeTag(int tagMask); 0437 0438 /** 0439 * Reparse the configuration. 0440 * Automated configuration changes are possible by modifying 0441 * the configuration file and then reparsing the configuration. 0442 */ 0443 void reparseConfiguration(); 0444 0445 /** 0446 * Play selected audio files. 0447 */ 0448 void playAudio(); 0449 0450 private slots: 0451 void onRenameActionsScheduled(); 0452 0453 private: 0454 Kid3Application* m_app; 0455 QString m_errorMsg; 0456 }; 0457 #else // HAVE_QTDBUS 0458 0459 #include <QObject> 0460 // Just to suppress moc "No relevant classes found" warning. 0461 class ScriptInterface : public QObject { 0462 Q_OBJECT 0463 }; 0464 0465 #endif // HAVE_QTDBUS