Permalink
Browse files

Updater work

  • Loading branch information...
lfranchi committed Oct 7, 2011
1 parent 3b86198 commit 687ed02df0fad8e6cf1afde4323502642232186c
View
@@ -75,6 +75,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
settingslistdelegate.cpp
resolversmodel.cpp
tomahawkwindow.cpp
+ LoadXSPFDialog.cpp
)
SET( tomahawkHeaders ${tomahawkHeaders}
@@ -124,6 +125,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
resolversmodel.h
delegateconfigwrapper.h
tomahawkwindow.h
+ LoadXSPFDialog.h
)
SET( tomahawkUI ${tomahawkUI}
@@ -135,6 +137,7 @@ SET( tomahawkUI ${tomahawkUI}
audiocontrols.ui
GetNewStuffDialog.ui
+ LoadXSPFDialog.ui
)
INCLUDE_DIRECTORIES(
View
@@ -0,0 +1,56 @@
+/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
+ *
+ * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
+ *
+ * Tomahawk is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Tomahawk 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "LoadXSPFDialog.h"
+
+#include "ui_LoadXSPFDialog.h"
+#include <QFileDialog>
+
+LoadXSPFDialog::LoadXSPFDialog( QWidget* parent, Qt::WindowFlags f )
+ : QDialog( parent, f )
+ , m_ui( new Ui_LoadXSPF )
+{
+ m_ui->setupUi( this );
+
+ connect( m_ui->buttonBox, SIGNAL( accepted() ), SLOT( accept() ) );
+ connect( m_ui->buttonBox, SIGNAL( rejected() ), SLOT( reject() ) );
+
+ connect( m_ui->navigateButton, SIGNAL( clicked( bool ) ), this, SLOT( getLocalFile() ) );
+}
+
+LoadXSPFDialog::~LoadXSPFDialog()
+{
+}
+
+void
+LoadXSPFDialog::getLocalFile()
+{
+ QString url = QFileDialog::getOpenFileName( this, tr( "Load XSPF File" ), QDir::homePath(), ".xspf" );
+ m_ui->lineEdit->setText( url );
+}
+
+QString LoadXSPFDialog::xspfUrl() const
+{
+ return m_ui->lineEdit->text();
+}
+
+bool
+LoadXSPFDialog::autoUpdate() const
+{
+ return m_ui->autoUpdate->isChecked();
+}
View
@@ -0,0 +1,43 @@
+/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
+ *
+ * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
+ *
+ * Tomahawk is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Tomahawk 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LOADXSPFDIALOG_H
+#define LOADXSPFDIALOG_H
+
+#include <QDialog>
+
+class Ui_LoadXSPF;
+
+class LoadXSPFDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ explicit LoadXSPFDialog( QWidget* parent = 0, Qt::WindowFlags f = 0 );
+ virtual ~LoadXSPFDialog();
+
+ QString xspfUrl() const;
+ bool autoUpdate() const;
+
+public slots:
+ void getLocalFile();
+
+private:
+ Ui_LoadXSPF* m_ui;
+};
+
+#endif // LOADXSPFDIALOG_H
View
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LoadXSPF</class>
+ <widget class="QDialog" name="LoadXSPF">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>332</width>
+ <height>86</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Load XSPF</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>XSPF Url:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEdit">
+ <property name="placeholderText">
+ <string>Enter URL...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="navigateButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="autoUpdate">
+ <property name="text">
+ <string>Automatically update</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>LoadXSPF</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>LoadXSPF</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
@@ -116,6 +116,7 @@ Playlist::Playlist( const source_ptr& src,
, m_lastmodified( lastmod )
, m_createdOn( createdOn )
, m_shared( shared )
+ , m_updater( 0 )
{
init();
}
@@ -138,6 +139,7 @@ Playlist::Playlist( const source_ptr& author,
, m_createdOn( 0 ) // will be set by db command
, m_shared( shared )
, m_initEntries( entries )
+ , m_updater( 0 )
{
init();
}
@@ -511,9 +513,12 @@ Playlist::addEntries( const QList<query_ptr>& queries, const QString& oldrev )
QList<plentry_ptr>
-Playlist::entriesFromQueries( const QList<Tomahawk::query_ptr>& queries )
+Playlist::entriesFromQueries( const QList<Tomahawk::query_ptr>& queries, bool clearFirst )
{
- QList<plentry_ptr> el = entries();
+ QList<plentry_ptr> el;
+ if ( !clearFirst )
+ el = entries();
+
foreach( const query_ptr& query, queries )
{
plentry_ptr e( new PlaylistEntry() );
View
@@ -36,10 +36,11 @@ class DatabaseCommand_LoadAllPlaylists;
class DatabaseCommand_LoadAllSortedPlaylists;
class DatabaseCommand_SetPlaylistRevision;
class DatabaseCommand_CreatePlaylist;
-
namespace Tomahawk
{
+class PlaylistUpdaterInterface;
+
class DLLEXPORT PlaylistEntry : public QObject
{
Q_OBJECT
@@ -196,7 +197,10 @@ friend class DynamicPlaylist;
virtual void setFilter( const QString& /*pattern*/ ) {}
- QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries );
+ QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries, bool clearFirst = false );
+ void setUpdater( PlaylistUpdaterInterface* interface ) const { m_updater = interface; }
+ PlaylistUpdaterInterface* updater() const { return m_updater; }
+
signals:
/// emitted when the playlist revision changes (whenever the playlist changes)
void revisionLoaded( Tomahawk::PlaylistRevision );
@@ -293,6 +297,8 @@ private slots:
QQueue<RevisionQueueItem> m_revisionQueue;
+ PlaylistUpdaterInterface* m_updater;
+
bool m_locallyChanged;
bool m_deleted;
bool m_busy;
@@ -22,6 +22,7 @@
#include "dllmacro.h"
#include "typedefs.h"
#include "playlist.h"
+#include <QTimer>
namespace Tomahawk
{
@@ -35,21 +36,40 @@ class DLLEXPORT PlaylistUpdaterInterface : public QObject
{
Q_OBJECT
public:
- PlaylistUpdaterInterface( const playlist_ptr& pl, QObject* parent )
- : QObject( parent )
+ PlaylistUpdaterInterface( const playlist_ptr& pl )
+ : QObject( pl.data() )
+ , m_timer( new QTimer( this ) )
, m_autoUpdate( true )
, m_playlist( pl )
- {}
+ {
+ Q_ASSERT( !m_playlist.isNull() );
+
+ m_playlist->setUpdater( this );
+ connect( m_timer, SIGNAL( timeout() ), this, SLOT( updateNow() ) );
+ }
virtual ~PlaylistUpdaterInterface() {}
- void setAutoUpdate( bool autoUpdate ) { m_autoUpdate = autoUpdate; }
+ void setAutoUpdate( bool autoUpdate ) {
+ m_autoUpdate = autoUpdate;
+ if ( m_autoUpdate )
+ m_timer->start();
+ else
+ m_timer->stop();
+ }
+
bool autoUpdate() const { return m_autoUpdate; }
+ void setInterval( int intervalMsecs ) { m_timer->setInterval( intervalMsecs ); }
+ int intervalMsecs() const { return m_timer->interval(); }
+
playlist_ptr playlist() const { return m_playlist; }
-signals:
+
+public slots:
+ virtual void updateNow() {}
private:
+ QTimer* m_timer;
bool m_autoUpdate;
playlist_ptr m_playlist;
};
@@ -25,23 +25,20 @@
using namespace Tomahawk;
-XspfUpdater::XspfUpdater( const playlist_ptr& pl, const QString& xUrl, QObject *parent )
- : PlaylistUpdaterInterface( pl, parent )
+XspfUpdater::XspfUpdater( const playlist_ptr& pl, const QString& xUrl )
+ : PlaylistUpdaterInterface( pl )
, m_url( xUrl )
- , m_timer( new QTimer( this ) )
{
- // for now refresh every 60min
- m_timer->setInterval( 60 * 60 * 1000);
- connect( m_timer, SIGNAL( timeout() ), this, SLOT( update() ) );
}
XspfUpdater::~XspfUpdater()
{}
void
-XspfUpdater::update()
+XspfUpdater::updateNow()
{
- XSPFLoader* l = new XSPFLoader( false );
+ XSPFLoader* l = new XSPFLoader( false, false );
+ l->load( m_url );
connect( l, SIGNAL( ok ( Tomahawk::playlist_ptr ) ), this, SLOT( playlistLoaded() ) );
}
@@ -52,7 +49,7 @@ XspfUpdater::playlistLoaded()
Q_ASSERT( loader );
QList< query_ptr > queries = loader->entries();
- QList<plentry_ptr> el = playlist()->entriesFromQueries( queries );
+ QList<plentry_ptr> el = playlist()->entriesFromQueries( queries, true );
playlist()->createNewRevision( uuid(), playlist()->currentrevision(), el );
// // if there are any different from the current playlist, clear and use the new one, update
Oops, something went wrong.

0 comments on commit 687ed02

Please sign in to comment.