X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fdialogs%2Fbookmarks.cpp;h=e84cb4fd62b8a4fc4a5ebf4935e649a163ad7064;hb=1dbee6584667999d489f12203807c1f3570bc9b4;hp=e3f65189f32b61b679fe169766c16d60ef85193c;hpb=033d2a6d5a7887f4b2c24312906799390e0f1080;p=vlc diff --git a/modules/gui/qt4/dialogs/bookmarks.cpp b/modules/gui/qt4/dialogs/bookmarks.cpp index e3f65189f3..e84cb4fd62 100644 --- a/modules/gui/qt4/dialogs/bookmarks.cpp +++ b/modules/gui/qt4/dialogs/bookmarks.cpp @@ -37,14 +37,21 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf ) { setWindowFlags( Qt::Tool ); setWindowOpacity( config_GetFloat( p_intf, "qt-opacity" ) ); - setWindowTitle( qtr( "Edit bookmark" ) ); + setWindowTitle( qtr( "Edit Bookmarks" ) ); QGridLayout *layout = new QGridLayout( this ); - QPushButton *addButton = new QPushButton( qtr( "Add" ) ); + QPushButton *addButton = new QPushButton( qtr( "Create" ) ); + addButton->setToolTip( qtr( "Create a new bookmark" ) ); QPushButton *delButton = new QPushButton( qtr( "Delete" ) ); + delButton->setToolTip( qtr( "Delete the selected item" ) ); QPushButton *clearButton = new QPushButton( qtr( "Clear" ) ); + clearButton->setToolTip( qtr( "Delete all the bookmarks" ) ); +#if 0 QPushButton *extractButton = new QPushButton( qtr( "Extract" ) ); + extractButton->setToolTip( qtr() ); +#endif + QPushButton *closeButton = new QPushButton( qtr( "&Close" ) ); bookmarksList = new QTreeWidget( this ); bookmarksList->setRootIsDecorated( false ); @@ -53,6 +60,8 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf ) bookmarksList->setSelectionBehavior( QAbstractItemView::SelectRows ); bookmarksList->setEditTriggers( QAbstractItemView::SelectedClicked ); bookmarksList->setColumnCount( 3 ); + bookmarksList->resize( sizeHint() ); + QStringList headerLabels; headerLabels << qtr( "Description" ); headerLabels << qtr( "Bytes" ); @@ -64,20 +73,27 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf ) 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 ); - layout->addWidget( bookmarksList, 0, 1, 6, 1); +#endif + layout->addWidget( bookmarksList, 0, 1, 6, 2); layout->setColumnStretch( 1, 1 ); + layout->addWidget( closeButton, 7, 2 ); CONNECT( bookmarksList, activated( QModelIndex ), this, activateItem( QModelIndex ) ); - CONNECT( bookmarksList, itemChanged( QTreeWidgetItem*, int ), this, edit( QTreeWidgetItem*, int ) ); + CONNECT( bookmarksList, itemChanged( QTreeWidgetItem*, int ), + this, edit( QTreeWidgetItem*, int ) ); BUTTONACT( addButton, add() ); BUTTONACT( delButton, del() ); BUTTONACT( clearButton, clear() ); +#if 0 BUTTONACT( extractButton, extract() ); +#endif + BUTTONACT( closeButton, close() ); - readSettings( "Bookmarks" ); + readSettings( "Bookmarks", QSize( 435, 206 ) ); updateGeometry(); } @@ -109,13 +125,19 @@ void BookmarksDialog::update() 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 ); + 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() @@ -124,18 +146,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 ); + if( !input_Control( p_input, INPUT_GET_BOOKMARK, &bookmark ) ) + { + bookmark.psz_name = qtu( THEMIM->getIM()->getName() + + QString("_%1" ).arg( bookmarksList->topLevelItemCount() ) ); + input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark ); + } update(); - } void BookmarksDialog::del() @@ -165,19 +184,22 @@ void BookmarksDialog::clear() 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; int i_bookmarks; if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, @@ -185,23 +207,49 @@ 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 ) ) ); + { + 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; + } + } + // Send the modification if( input_Control( p_input, INPUT_CHANGE_BOOKMARK, p_seekpoint, i_edit ) != VLC_SUCCESS ) - return; + goto clear; + // Everything goes fine : update update(); +// Clear the bookmark list +clear: + for( int i = 0; i < i_bookmarks; i++) + { + if( p_seekpoint != pp_bookmarks[i] ) + vlc_seekpoint_Delete( pp_bookmarks[i] ); + } + free( pp_bookmarks ); } void BookmarksDialog::extract()