1 /*****************************************************************************
2 * bookmarks.cpp : Bookmarks
3 ****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
6 * Authors: Antoine Lejeune <phytos@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
26 #include "dialogs/bookmarks.hpp"
27 #include "dialogs_provider.hpp"
28 #include "input_manager.hpp"
30 #include <QGridLayout>
31 #include <QSpacerItem>
32 #include <QPushButton>
34 BookmarksDialog
*BookmarksDialog::instance
= NULL
;
36 BookmarksDialog::BookmarksDialog( intf_thread_t
*_p_intf
):QVLCFrame( _p_intf
)
38 setWindowFlags( Qt::Tool
);
39 setWindowOpacity( config_GetFloat( p_intf
, "qt-opacity" ) );
40 setWindowTitle( qtr( "Edit Bookmarks" ) );
42 QGridLayout
*layout
= new QGridLayout( this );
44 QPushButton
*addButton
= new QPushButton( qtr( "Create" ) );
45 addButton
->setToolTip( qtr( "Create a new bookmark" ) );
46 QPushButton
*delButton
= new QPushButton( qtr( "Delete" ) );
47 delButton
->setToolTip( qtr( "Delete the selected item" ) );
48 QPushButton
*clearButton
= new QPushButton( qtr( "Clear" ) );
49 clearButton
->setToolTip( qtr( "Delete all the bookmarks" ) );
51 QPushButton
*extractButton
= new QPushButton( qtr( "Extract" ) );
52 extractButton
->setToolTip( qtr() );
54 QPushButton
*closeButton
= new QPushButton( qtr( "&Close" ) );
56 bookmarksList
= new QTreeWidget( this );
57 bookmarksList
->setRootIsDecorated( false );
58 bookmarksList
->setAlternatingRowColors( true );
59 bookmarksList
->setSelectionMode( QAbstractItemView::ExtendedSelection
);
60 bookmarksList
->setSelectionBehavior( QAbstractItemView::SelectRows
);
61 bookmarksList
->setEditTriggers( QAbstractItemView::SelectedClicked
);
62 bookmarksList
->setColumnCount( 3 );
63 bookmarksList
->resize( sizeHint() );
65 QStringList headerLabels
;
66 headerLabels
<< qtr( "Description" );
67 headerLabels
<< qtr( "Bytes" );
68 headerLabels
<< qtr( "Time" );
69 bookmarksList
->setHeaderLabels( headerLabels
);
72 layout
->addWidget( addButton
, 0, 0 );
73 layout
->addWidget( delButton
, 1, 0 );
74 layout
->addWidget( clearButton
, 2, 0 );
75 layout
->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding
), 4, 0 );
77 layout
->addWidget( extractButton
, 5, 0 );
79 layout
->addWidget( bookmarksList
, 0, 1, 6, 2);
80 layout
->setColumnStretch( 1, 1 );
81 layout
->addWidget( closeButton
, 7, 2 );
83 CONNECT( bookmarksList
, activated( QModelIndex
), this,
84 activateItem( QModelIndex
) );
85 CONNECT( bookmarksList
, itemChanged( QTreeWidgetItem
*, int ),
86 this, edit( QTreeWidgetItem
*, int ) );
88 BUTTONACT( addButton
, add() );
89 BUTTONACT( delButton
, del() );
90 BUTTONACT( clearButton
, clear() );
92 BUTTONACT( extractButton
, extract() );
94 BUTTONACT( closeButton
, close() );
96 readSettings( "Bookmarks", QSize( 435, 206 ) );
100 BookmarksDialog::~BookmarksDialog()
102 writeSettings( "Bookmarks" );
105 void BookmarksDialog::update()
107 input_thread_t
*p_input
= THEMIM
->getInput();
108 if( !p_input
) return;
110 seekpoint_t
**pp_bookmarks
;
113 if( bookmarksList
->topLevelItemCount() > 0 )
115 bookmarksList
->model()->removeRows( 0, bookmarksList
->topLevelItemCount() );
118 if( input_Control( p_input
, INPUT_GET_BOOKMARKS
, &pp_bookmarks
,
119 &i_bookmarks
) != VLC_SUCCESS
)
122 for( int i
= 0; i
< i_bookmarks
; i
++ )
124 // List with the differents elements of the row
126 row
<< QString( pp_bookmarks
[i
]->psz_name
);
127 row
<< QString( "%1" ).arg( pp_bookmarks
[i
]->i_byte_offset
);
128 row
<< QString( "%1" ).arg( pp_bookmarks
[i
]->i_time_offset
/ 1000000 );
129 QTreeWidgetItem
*item
= new QTreeWidgetItem( bookmarksList
, row
);
130 item
->setFlags( Qt::ItemIsSelectable
| Qt::ItemIsEditable
|
131 Qt::ItemIsUserCheckable
| Qt::ItemIsEnabled
);
132 bookmarksList
->insertTopLevelItem( i
, item
);
137 void BookmarksDialog::add()
139 input_thread_t
*p_input
= THEMIM
->getInput();
140 if( !p_input
) return;
142 seekpoint_t bookmark
;
144 bookmark
.psz_name
= qtu( THEMIM
->getIM()->getName() +
145 QString("_%1" ).arg( bookmarksList
->topLevelItemCount() ) );
146 bookmark
.i_byte_offset
= 0;
147 bookmark
.i_time_offset
= 0;
149 input_Control( p_input
, INPUT_GET_BYTE_POSITION
, &bookmark
.i_byte_offset
);
150 var_Get( p_input
, "time", &pos
);
151 bookmark
.i_time_offset
= pos
.i_time
;
152 input_Control( p_input
, INPUT_ADD_BOOKMARK
, &bookmark
);
158 void BookmarksDialog::del()
160 input_thread_t
*p_input
= THEMIM
->getInput();
161 if( !p_input
) return;
163 int i_focused
= bookmarksList
->currentIndex().row();
167 input_Control( p_input
, INPUT_DEL_BOOKMARK
, i_focused
);
173 void BookmarksDialog::clear()
175 input_thread_t
*p_input
= THEMIM
->getInput();
176 if( !p_input
) return;
178 input_Control( p_input
, INPUT_CLEAR_BOOKMARKS
);
183 void BookmarksDialog::edit( QTreeWidgetItem
*item
, int column
)
185 // We can only edit a item if it is the last item selected
186 if( bookmarksList
->selectedItems().isEmpty() ||
187 bookmarksList
->selectedItems().last() != item
)
190 input_thread_t
*p_input
= THEMIM
->getInput();
191 if( !p_input
) return;
193 // We get the row number of the item
194 int i_edit
= bookmarksList
->indexOfTopLevelItem( item
);
196 // We get the bookmarks list
197 seekpoint_t
**pp_bookmarks
;
200 if( input_Control( p_input
, INPUT_GET_BOOKMARKS
, &pp_bookmarks
,
201 &i_bookmarks
) != VLC_SUCCESS
)
204 if( i_edit
>= i_bookmarks
)
207 // We modify the seekpoint
208 seekpoint_t
*p_seekpoint
= pp_bookmarks
[i_edit
];
210 p_seekpoint
->psz_name
= strdup( qtu( item
->text( column
) ) );
211 else if( column
== 1 )
212 p_seekpoint
->i_byte_offset
= atoi( qtu( item
->text( column
) ) );
213 else if( column
== 2 )
214 p_seekpoint
->i_time_offset
= 1000000 * atoll( qtu( item
->text( column
) ) );
216 if( input_Control( p_input
, INPUT_CHANGE_BOOKMARK
, p_seekpoint
, i_edit
) !=
224 void BookmarksDialog::extract()
229 void BookmarksDialog::activateItem( QModelIndex index
)
231 input_thread_t
*p_input
= THEMIM
->getInput();
232 if( !p_input
) return;
234 input_Control( p_input
, INPUT_SET_BOOKMARK
, index
.row() );