]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/bookmarks.cpp
podcast: save configuration when adding/removing podcast from the dialog.
[vlc] / modules / gui / qt4 / dialogs / bookmarks.cpp
index 097150e37f52f4624f285a4e1a813ae1bd08ee99..9fa7615007094e18de85fcff3ae66a749314025f 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
 #include "dialogs/bookmarks.hpp"
-#include "dialogs_provider.hpp"
 #include "input_manager.hpp"
 
 #include <QGridLayout>
@@ -80,6 +80,9 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
     layout->setColumnStretch( 1, 1 );
     layout->addWidget( closeButton, 7, 2 );
 
+    CONNECT( THEMIM->getIM(), bookmarksChanged(),
+             this, update() );
+
     CONNECT( bookmarksList, activated( QModelIndex ), this,
              activateItem( QModelIndex ) );
     CONNECT( bookmarksList, itemChanged( QTreeWidgetItem*, int ),
@@ -93,7 +96,7 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
 #endif
     BUTTONACT( closeButton, close() );
 
-    readSettings( "Bookmarks", QSize( 435, 206 ) );
+    readSettings( "Bookmarks", QSize( 435, 280 ) );
     updateGeometry();
 }
 
@@ -123,15 +126,21 @@ void BookmarksDialog::update()
     {
         // List with the differents elements of the row
         QStringList row;
-        row << QString( pp_bookmarks[i]->psz_name );
-        row << QString( "%1" ).arg( pp_bookmarks[i]->i_byte_offset );
-        row << QString( "%1" ).arg( pp_bookmarks[i]->i_time_offset / 1000000 );
+        row << QString( qfu( pp_bookmarks[i]->psz_name ) );
+        row << QString::number( pp_bookmarks[i]->i_byte_offset );
+        int total = pp_bookmarks[i]->i_time_offset/ 1000000;
+        int hour = total / (60*60);
+        int min = (total - hour*60*60) / 60;
+        int sec = total - hour*60*60 - min*60;
+        QString str;
+        row << str.sprintf("%02d:%02d:%02d", hour, min, sec );
         QTreeWidgetItem *item = new QTreeWidgetItem( bookmarksList, row );
         item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable |
                         Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
         bookmarksList->insertTopLevelItem( i, item );
+        vlc_seekpoint_Delete( pp_bookmarks[i] );
     }
-
+    free( pp_bookmarks );
 }
 
 void BookmarksDialog::add()
@@ -140,19 +149,14 @@ void BookmarksDialog::add()
     if( !p_input ) return;
 
     seekpoint_t bookmark;
-    vlc_value_t pos;
-    bookmark.psz_name = qtu( THEMIM->getIM()->getName() +
-                    QString("_%1" ).arg( bookmarksList->topLevelItemCount() ) );
-    bookmark.i_byte_offset = 0;
-    bookmark.i_time_offset = 0;
 
-    input_Control( p_input, INPUT_GET_BYTE_POSITION, &bookmark.i_byte_offset );
-    var_Get( p_input, "time", &pos );
-    bookmark.i_time_offset = pos.i_time;
-    input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark );
-
-    update();
+    if( !input_Control( p_input, INPUT_GET_BOOKMARK, &bookmark ) )
+    {
+        bookmark.psz_name = const_cast<char *>qtu( THEMIM->getIM()->getName() +
+                   QString::number( bookmarksList->topLevelItemCount() ) );
 
+        input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark );
+    }
 }
 
 void BookmarksDialog::del()
@@ -166,8 +170,6 @@ void BookmarksDialog::del()
     {
         input_Control( p_input, INPUT_DEL_BOOKMARK, i_focused );
     }
-
-    update();
 }
 
 void BookmarksDialog::clear()
@@ -176,25 +178,26 @@ void BookmarksDialog::clear()
     if( !p_input ) return;
 
     input_Control( p_input, INPUT_CLEAR_BOOKMARKS );
-
-    update();
 }
 
 void BookmarksDialog::edit( QTreeWidgetItem *item, int column )
 {
+    QStringList fields;
     // We can only edit a item if it is the last item selected
     if( bookmarksList->selectedItems().isEmpty() ||
         bookmarksList->selectedItems().last() != item )
         return;
 
     input_thread_t *p_input = THEMIM->getInput();
-    if( !p_input ) return;
+    if( !p_input )
+        return;
 
     // We get the row number of the item
     int i_edit = bookmarksList->indexOfTopLevelItem( item );
 
     // We get the bookmarks list
-    seekpoint_t **pp_bookmarks;
+    seekpoint_t** pp_bookmarks;
+    seekpoint_t*  p_seekpoint = NULL;
     int i_bookmarks;
 
     if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
@@ -202,23 +205,41 @@ void BookmarksDialog::edit( QTreeWidgetItem *item, int column )
         return;
 
     if( i_edit >= i_bookmarks )
-        return;
+        goto clear;
 
     // We modify the seekpoint
-    seekpoint_t *p_seekpoint = pp_bookmarks[i_edit];
+    p_seekpoint = pp_bookmarks[i_edit];
     if( column == 0 )
+    {
+        free( p_seekpoint->psz_name );
         p_seekpoint->psz_name = strdup( qtu( item->text( column ) ) );
+    }
     else if( column == 1 )
         p_seekpoint->i_byte_offset = atoi( qtu( item->text( column ) ) );
     else if( column == 2 )
-        p_seekpoint->i_time_offset = 1000000 * atoll( qtu( item->text( column ) ) );
-
-    if( input_Control( p_input, INPUT_CHANGE_BOOKMARK, p_seekpoint, i_edit ) !=
-        VLC_SUCCESS )
-        return;
+    {
+        fields = item->text( column ).split( ":", QString::SkipEmptyParts );
+        if( fields.size() == 1 )
+            p_seekpoint->i_time_offset = 1000000 * ( fields[0].toInt() );
+        else if( fields.size() == 2 )
+            p_seekpoint->i_time_offset = 1000000 * ( fields[0].toInt() * 60 + fields[1].toInt() );
+        else if( fields.size() == 3 )
+            p_seekpoint->i_time_offset = 1000000 * ( fields[0].toInt() * 3600 + fields[1].toInt() * 60 + fields[2].toInt() );
+        else
+        {
+            msg_Err( p_intf, "Invalid string format for time" );
+            goto clear;
+        }
+    }
 
-    update();
+    // Send the modification
+    input_Control( p_input, INPUT_CHANGE_BOOKMARK, p_seekpoint, i_edit );
 
+clear:
+    // Clear the bookmark list
+    for( int i = 0; i < i_bookmarks; i++)
+        vlc_seekpoint_Delete( pp_bookmarks[i] );
+    free( pp_bookmarks );
 }
 
 void BookmarksDialog::extract()