]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/bookmarks.cpp
Qt4: Fixed uninitialized variable
[vlc] / modules / gui / qt4 / dialogs / bookmarks.cpp
index 68f0fa4ff07097b2aff83bef16e3773cdfe8b96c..8b6ba9d73c5100be227cfb651f9ced0ed2575652 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>
+#include <QHBoxLayout>
 #include <QSpacerItem>
 #include <QPushButton>
-
-BookmarksDialog *BookmarksDialog::instance = NULL;
+#include <QDialogButtonBox>
 
 BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
 {
     setWindowFlags( Qt::Tool );
-    setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) );
+    setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
     setWindowTitle( qtr( "Edit Bookmarks" ) );
+    setWindowRole( "vlc-bookmarks" );
 
-    QGridLayout *layout = new QGridLayout( this );
+    QHBoxLayout *layout = new QHBoxLayout( this );
 
+    QDialogButtonBox *buttonsBox = new QDialogButtonBox( Qt::Vertical );
     QPushButton *addButton = new QPushButton( qtr( "Create" ) );
     addButton->setToolTip( qtr( "Create a new bookmark" ) );
+    buttonsBox->addButton( addButton, QDialogButtonBox::ActionRole );
     QPushButton *delButton = new QPushButton( qtr( "Delete" ) );
     delButton->setToolTip( qtr( "Delete the selected item" ) );
+    buttonsBox->addButton( delButton, QDialogButtonBox::ActionRole );
     QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
     clearButton->setToolTip( qtr( "Delete all the bookmarks" ) );
+    buttonsBox->addButton( clearButton, QDialogButtonBox::ResetRole );
 #if 0
     QPushButton *extractButton = new QPushButton( qtr( "Extract" ) );
     extractButton->setToolTip( qtr() );
+    buttonsBox->addButton( extractButton, QDialogButtonBox::ActionRole );
 #endif
-    QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
+    /* ?? Feels strange as Qt guidelines will put reject on top */
+    buttonsBox->addButton( new QPushButton( qtr( "&Close" ) ),
+                          QDialogButtonBox::RejectRole);
 
     bookmarksList = new QTreeWidget( this );
     bookmarksList->setRootIsDecorated( false );
@@ -68,17 +75,11 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
     headerLabels << qtr( "Time" );
     bookmarksList->setHeaderLabels( headerLabels );
 
+    layout->addWidget( buttonsBox );
+    layout->addWidget( bookmarksList );
 
-    layout->addWidget( addButton, 0, 0 );
-    layout->addWidget( delButton, 1, 0 );
-    layout->addWidget( clearButton, 2, 0 );
-    layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ), 4, 0 );
-#if 0
-    layout->addWidget( extractButton, 5, 0 );
-#endif
-    layout->addWidget( bookmarksList, 0, 1, 6, 2);
-    layout->setColumnStretch( 1, 1 );
-    layout->addWidget( closeButton, 7, 2 );
+    CONNECT( THEMIM->getIM(), bookmarksChanged(),
+             this, update() );
 
     CONNECT( bookmarksList, activated( QModelIndex ), this,
              activateItem( QModelIndex ) );
@@ -91,9 +92,9 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
 #if 0
     BUTTONACT( extractButton, extract() );
 #endif
-    BUTTONACT( closeButton, close() );
+    CONNECT( buttonsBox, rejected(), this, close() );
 
-    readSettings( "Bookmarks" );
+    readSettings( "Bookmarks", QSize( 435, 280 ) );
     updateGeometry();
 }
 
@@ -108,7 +109,7 @@ void BookmarksDialog::update()
     if( !p_input ) return;
 
     seekpoint_t **pp_bookmarks;
-    int i_bookmarks;
+    int i_bookmarks = 0;
 
     if( bookmarksList->topLevelItemCount() > 0 )
     {
@@ -123,15 +124,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,18 +147,15 @@ void BookmarksDialog::add()
     if( !p_input ) return;
 
     seekpoint_t bookmark;
-    vlc_value_t pos;
-    bookmark.psz_name = NULL;
-    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 ) )
+    {
+        QString name = THEMIM->getIM()->getName()
+                     + QString::number( bookmarksList->topLevelItemCount() );
+        bookmark.psz_name = const_cast<char *>qtu( name );
 
+        input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark );
+    }
 }
 
 void BookmarksDialog::del()
@@ -165,8 +169,6 @@ void BookmarksDialog::del()
     {
         input_Control( p_input, INPUT_DEL_BOOKMARK, i_focused );
     }
-
-    update();
 }
 
 void BookmarksDialog::clear()
@@ -175,25 +177,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,
@@ -201,23 +204,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.count() == 1 )
+            p_seekpoint->i_time_offset = 1000000 * ( fields[0].toInt() );
+        else if( fields.count() == 2 )
+            p_seekpoint->i_time_offset = 1000000 * ( fields[0].toInt() * 60 + fields[1].toInt() );
+        else if( fields.count() == 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()