File indexing completed on 2025-01-05 04:26:50
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Anmol Ahuja <darthcodus@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_BOOKMARK_SCRIPT_H 0018 #define AMAROK_BOOKMARK_SCRIPT_H 0019 0020 #include "amarokurls/BookmarkGroup.h" 0021 #include "core/meta/Meta.h" 0022 0023 #include <QJSValue> 0024 #include <QObject> 0025 #include <QMap> 0026 #include <QMetaType> 0027 0028 class QJSEngine; 0029 0030 typedef QMap< QString, QString > StringMap; 0031 0032 namespace AmarokScript 0033 { 0034 // SCRIPTDOX Amarok.Bookmark 0035 class AmarokBookmarkScript : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 explicit AmarokBookmarkScript( QJSEngine* scriptEngine ); 0041 0042 /** 0043 * @return bookmark for the current context view. 0044 */ 0045 Q_INVOKABLE AmarokUrlPtr contextView(); 0046 0047 /** 0048 * @return bookmark for the current playlist view. 0049 */ 0050 Q_INVOKABLE AmarokUrlPtr currentPlaylistView(); 0051 0052 /** 0053 * * @return bookmark for the current browser view. 0054 */ 0055 Q_INVOKABLE AmarokUrlPtr browserView(); 0056 0057 /** 0058 * Bookmark the current track at the current position. 0059 */ 0060 Q_INVOKABLE AmarokUrlPtr createCurrentTrackBookmark(); 0061 0062 /** 0063 * Wraps the invocation to BookmarkPrototype::bookmarkCtor so it can bind to a QJSEngine 0064 */ 0065 Q_INVOKABLE QJSValue bookmarkCtorWrapper( QJSValue arg0, QJSValue arg1 = QJSValue(QJSValue::UndefinedValue ) ); 0066 0067 /** 0068 * Wraps the invocation to BookmarkGroupPrototype::bookmarkGroupCtor so it can bind to a QJSEngine 0069 */ 0070 Q_INVOKABLE QJSValue bookmarkGroupCtorWrapper( QJSValue arg0, QJSValue arg1 = QJSValue(QJSValue::UndefinedValue ) ); 0071 0072 private: 0073 0074 QJSEngine *m_engine; 0075 0076 }; 0077 0078 class BookmarkPrototype : public QObject 0079 { 0080 Q_OBJECT 0081 0082 Q_PROPERTY( int id READ id WRITE setId ) 0083 Q_PROPERTY( BookmarkGroupPtr parent READ parent WRITE setParent ) 0084 Q_PROPERTY( QString command READ command WRITE setCommand ) 0085 Q_PROPERTY( QString name READ name WRITE setName ) 0086 Q_PROPERTY( QString path READ path WRITE setPath ) 0087 Q_PROPERTY( QString description READ description WRITE setDescription ) 0088 Q_PROPERTY( bool isNull READ isNull ) 0089 Q_PROPERTY( QString customValue READ customValue WRITE setCustomValue ) 0090 Q_PROPERTY( QString url READ url ) 0091 0092 public: 0093 explicit BookmarkPrototype( const AmarokUrlPtr &bookmark ); 0094 static QJSValue bookmarkCtor( QJSValue &arg0, QJSValue &arg1, QJSEngine *engine ); 0095 AmarokUrlPtr data() const { return m_url; } 0096 0097 /** 0098 * Save the bookmark to db. Must not be null. 0099 */ 0100 Q_INVOKABLE bool save(); 0101 Q_INVOKABLE void initFromString( const QString & urlString ); 0102 Q_INVOKABLE bool run(); 0103 Q_INVOKABLE void removeFromDb(); 0104 Q_INVOKABLE QString prettyCommand() const; 0105 Q_INVOKABLE StringMap args() const; 0106 0107 /** 0108 * Sets the url argument named @p name to @p value. Overrides any possible 0109 * previous value. 0110 * 0111 * @param name The name of the url argument. 0112 * @param value The value. 0113 */ 0114 Q_INVOKABLE void setArg( const QString &name, const QString &value ); 0115 0116 private: 0117 void setId( int id ); 0118 int id() const; 0119 void setParent( const BookmarkGroupPtr &parent ); 0120 QString command() const; 0121 void setCommand( const QString &command ); 0122 void setName( const QString &name ); 0123 QString name() const; 0124 QString path() const; 0125 void setPath( const QString &path ); 0126 QString description() const; 0127 BookmarkGroupPtr parent() const; 0128 void setDescription( const QString &description ); 0129 void setCustomValue( const QString &custom ); 0130 QString customValue() const; 0131 QString url() const; 0132 bool isNull() const; 0133 0134 AmarokUrlPtr m_url; 0135 }; 0136 0137 class BookmarkGroupPrototype : public QObject 0138 { 0139 Q_OBJECT 0140 0141 Q_PROPERTY( int id READ id ) 0142 Q_PROPERTY( BookmarkGroupPtr parent READ parent WRITE setParent ) 0143 Q_PROPERTY( QString name READ name WRITE setName ) 0144 Q_PROPERTY( QString description READ description WRITE setDescription ) 0145 Q_PROPERTY( int childCount READ childCount ) 0146 0147 public: 0148 explicit BookmarkGroupPrototype( const BookmarkGroupPtr &group ); 0149 static QJSValue bookmarkGroupCtor( QJSValue &arg0, QJSValue &arg1, QJSEngine *engine); 0150 BookmarkGroupPtr data() const { return m_group; } 0151 0152 /** 0153 * Save the bookmark group to db. 0154 */ 0155 Q_INVOKABLE void save(); 0156 Q_INVOKABLE BookmarkGroupList childGroups() const; 0157 Q_INVOKABLE BookmarkList childBookmarks() const; 0158 Q_INVOKABLE void clear(); 0159 Q_INVOKABLE void deleteChildBookmark( const AmarokUrlPtr &bookmark ); 0160 Q_INVOKABLE void deleteChildBookmarkgroup( const BookmarkGroupPtr &bookmarkGroup ); 0161 0162 private: 0163 int id() const; 0164 QString name() const; 0165 QString description() const; 0166 int childCount() const; 0167 void setName( const QString &name ); 0168 void setDescription( const QString &description ); 0169 BookmarkGroupPtr parent() const; 0170 void setParent( const BookmarkGroupPtr &parent ); 0171 0172 BookmarkGroupPtr m_group; 0173 }; 0174 } 0175 0176 #endif