~ubuntu-branches/ubuntu/maverick/transmission/maverick-updates

« back to all changes in this revision

Viewing changes to qt/mainwin.cc

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2009-12-08 10:49:11 UTC
  • mfrom: (1.1.29 upstream) (2.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20091208104911-06gio45n2nla3vpg
Tags: 1.80~b1-0ubuntu1
* New upstream release (LP: #460620), rebased on debian unstable
  remaining changes:
  - debian/control:
    + Added replaces & provides clutch (now included as part of transmission).
      Can be removed in lucid+1
    + Added quilt, liblaunchpad-integration-dev and lsb-release to Build-Depends
  - debian/rules:
    + create a po template during package build.
  - debian/patches/01_lpi.patch:
    + integrate transmission with launchpad
  - debian/patches/20_add_x-ubuntu-gettext-domain.diff:
    + add x-ubuntu-gettext-domain to .desktop file.
  - debian/transmission-daemon.default:
    - remove --auth from OPTIONS
* Fixes bugs:
  - tray menu shows wrong status for "main window" when started minimized
    (LP: #451415)
* Refreshed patches:
  - dont_build_libevent.patch
  - 99_autoreconf.patch
* Removed patches:
  - 21_onPortTested.diff, 23_tr_torrentNext.diff and
    24_tr_torrentDeleteLocalData_do_move.diff
* debian/patches/21_fix_inhibition.patch:
  - The right value for suspend inhibition is 4
* debian/control:
  - Build-Depend on libgconf2-dev to enable magnet link registration and on
    libcanberra-gtk-dev for notification sound.
* debian/watch:
  - make it detect beta versions, to be removed after 1.80 is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
 
2
 * This file Copyright (C) 2009 Mnemosyne LLC
3
3
 *
4
4
 * This file is licensed by the GPL version 2.  Works owned by the
5
5
 * Transmission project are granted a special exemption to clause 2(b)
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: mainwin.cc 8890 2009-08-11 18:57:49Z charles $
 
10
 * $Id: mainwin.cc 9671 2009-12-05 02:19:24Z charles $
11
11
 */
12
12
 
13
13
#include <cassert>
14
14
#include <iostream>
15
15
 
16
16
#include <QCheckBox>
 
17
#include <QCloseEvent>
17
18
#include <QDesktopServices>
18
19
#include <QFileDialog>
 
20
#include <QHBoxLayout>
 
21
#include <QInputDialog>
19
22
#include <QLabel>
 
23
#include <QSignalMapper>
20
24
#include <QSize>
21
25
#include <QStyle>
22
 
#include <QHBoxLayout>
23
26
#include <QSystemTrayIcon>
24
27
#include <QUrl>
25
 
#include <QSignalMapper>
26
28
 
27
29
#include <libtransmission/version.h>
28
30
 
109
111
    const QSize smallIconSize( i, i );
110
112
 
111
113
    // icons
112
 
    ui.action_Add->setIcon( getStockIcon( "list-add", QStyle::SP_DialogOpenButton ) );
 
114
    ui.action_AddFile->setIcon( getStockIcon( "list-add", QStyle::SP_DialogOpenButton ) );
113
115
    ui.action_New->setIcon( getStockIcon( "document-new", QStyle::SP_DesktopIcon ) );
114
116
    ui.action_Properties->setIcon( getStockIcon( "document-properties", QStyle::SP_DesktopIcon ) );
115
117
    ui.action_OpenFolder->setIcon( getStockIcon( "folder-open", QStyle::SP_DirOpenIcon ) );
151
153
    connect( ui.action_Announce, SIGNAL(triggered()), this, SLOT(reannounceSelected()) );
152
154
    connect( ui.action_StartAll, SIGNAL(triggered()), this, SLOT(startAll()));
153
155
    connect( ui.action_PauseAll, SIGNAL(triggered()), this, SLOT(pauseAll()));
154
 
    connect( ui.action_Add, SIGNAL(triggered()), this, SLOT(openTorrent()));
 
156
    connect( ui.action_AddFile, SIGNAL(triggered()), this, SLOT(openTorrent()));
 
157
    connect( ui.action_AddURL, SIGNAL(triggered()), this, SLOT(openURL()));
155
158
    connect( ui.action_New, SIGNAL(triggered()), this, SLOT(newTorrent()));
156
159
    connect( ui.action_Preferences, SIGNAL(triggered()), myPrefsDialog, SLOT(show()));
157
160
    connect( ui.action_Statistics, SIGNAL(triggered()), myStatsDialog, SLOT(show()));
158
161
    connect( ui.action_About, SIGNAL(triggered()), myAboutDialog, SLOT(show()));
159
162
    connect( ui.action_Contents, SIGNAL(triggered()), this, SLOT(openHelp()));
160
163
    connect( ui.action_OpenFolder, SIGNAL(triggered()), this, SLOT(openFolder()));
 
164
    connect( ui.action_CopyMagnetToClipboard, SIGNAL(triggered()), this, SLOT(copyMagnetLinkToClipboard()));
161
165
    connect( ui.action_SetLocation, SIGNAL(triggered()), this, SLOT(setLocation()));
162
166
    connect( ui.action_Properties, SIGNAL(triggered()), this, SLOT(openProperties()));
163
167
    connect( ui.action_SessionDialog, SIGNAL(triggered()), mySessionDialog, SLOT(show()));
165
169
 
166
170
    QAction * sep2 = new QAction( this );
167
171
    sep2->setSeparator( true );
 
172
    QAction * sep3 = new QAction( this );
 
173
    sep3->setSeparator( true );
168
174
 
169
175
    // context menu
170
176
    QList<QAction*> actions;
171
177
    actions << ui.action_Properties
172
178
            << ui.action_OpenFolder
173
 
            << ui.action_SetLocation
174
179
            << sep2
175
180
            << ui.action_Start
 
181
            << ui.action_Announce
176
182
            << ui.action_Pause
 
183
            << ui.action_CopyMagnetToClipboard
 
184
            << sep3
177
185
            << ui.action_Verify
178
 
            << ui.action_Announce
 
186
            << ui.action_SetLocation
179
187
            << sep
180
188
            << ui.action_Remove
181
189
            << ui.action_Delete;
213
221
    actionGroup->addAction( ui.action_SortByTracker );
214
222
 
215
223
    QMenu * menu = new QMenu( );
216
 
    menu->addAction( ui.action_Add );
 
224
    menu->addAction( ui.action_AddFile );
 
225
    menu->addAction( ui.action_AddURL );
217
226
    menu->addSeparator( );
218
227
    menu->addAction( ui.action_ShowMainWindow );
219
228
    menu->addAction( ui.action_ShowMessageLog );
286
295
****/
287
296
 
288
297
void
 
298
TrMainWindow :: closeEvent( QCloseEvent * event )
 
299
{
 
300
    // if they're using a tray icon, close to the tray
 
301
    // instead of exiting
 
302
    if( !myPrefs.getBool( Prefs :: SHOW_TRAY_ICON ) )
 
303
        event->accept( );
 
304
    else {
 
305
        toggleWindows( false );
 
306
        event->ignore( );
 
307
    }
 
308
}
 
309
 
 
310
/****
 
311
*****
 
312
****/
 
313
 
 
314
void
289
315
TrMainWindow :: onSessionSourceChanged( )
290
316
{
291
317
    myModel.clear( );
460
486
        connect( ui.action_SessionRatio, SIGNAL(triggered()), this, SLOT(showSessionRatio()));
461
487
        connect( ui.action_SessionTransfer, SIGNAL(triggered()), this, SLOT(showSessionTransfer()));
462
488
        p = myStatsModeButton = new TrIconPushButton( this );
463
 
        p->setIcon( getStockIcon( "view-refresh", QStyle::SP_BrowserReload ) );
 
489
        p->setIcon( QIcon( ":/icons/ratio.png" ) );
464
490
        p->setFlat( true );
465
491
        p->setMenu( m );
466
492
        h->addWidget( p );  
635
661
}
636
662
 
637
663
void
 
664
TrMainWindow :: copyMagnetLinkToClipboard( )
 
665
{
 
666
    const int id( *getSelectedTorrents().begin() );
 
667
    mySession.copyMagnetLinkToClipboard( id );
 
668
}
 
669
 
 
670
void
638
671
TrMainWindow :: openHelp( )
639
672
{
640
673
    const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
700
733
        str = tr( "Down: %1, Up: %2" ).arg( Utils :: sizeToString( stats.downloadedBytes ) )
701
734
                                      .arg( Utils :: sizeToString( stats.uploadedBytes ) );
702
735
    }
703
 
    else /* default is "total-ratio" */
 
736
    else // default is "total-ratio"
704
737
    {
705
738
        str = tr( "Ratio: %1" ).arg( Utils :: ratioToString( mySession.getCumulativeStats().ratio ) );
706
739
    }
719
752
    const QItemSelectionModel * selectionModel( ui.listView->selectionModel( ) );
720
753
    const int rowCount( model->rowCount( ) );
721
754
 
722
 
    /* count how many torrents are selected, paused, etc */
 
755
    // count how many torrents are selected, paused, etc
723
756
    for( int row=0; row<rowCount; ++row ) {
724
757
        const QModelIndex modelIndex( model->index( row, 0 ) );
725
758
        assert( model == modelIndex.model( ) );
726
759
        const Torrent * tor( model->data( modelIndex, TorrentModel::TorrentRole ).value<const Torrent*>( ) );
727
 
        const bool isSelected( selectionModel->isSelected( modelIndex ) );
728
 
        const bool isPaused( tor->isPaused( ) );
729
 
        if( isSelected )
730
 
            ++selected;
731
 
        if( isPaused )
732
 
            ++ paused;
733
 
        if( isSelected && isPaused )
734
 
            ++selectedAndPaused;
735
 
        if( tor->canManualAnnounce( ) )
736
 
            ++canAnnounce;
 
760
        if( tor ) {
 
761
            const bool isSelected( selectionModel->isSelected( modelIndex ) );
 
762
            const bool isPaused( tor->isPaused( ) );
 
763
            if( isSelected )
 
764
                ++selected;
 
765
            if( isPaused )
 
766
                ++ paused;
 
767
            if( isSelected && isPaused )
 
768
                ++selectedAndPaused;
 
769
            if( tor->canManualAnnounce( ) )
 
770
                ++canAnnounce;
 
771
        }
737
772
    }
738
773
 
739
774
    const bool haveSelection( selected > 0 );
746
781
 
747
782
    const bool oneSelection( selected == 1 );
748
783
    ui.action_OpenFolder->setEnabled( oneSelection && mySession.isLocal( ) );
 
784
    ui.action_CopyMagnetToClipboard->setEnabled( oneSelection );
749
785
 
750
786
    ui.action_SelectAll->setEnabled( selected < rowCount );
751
787
    ui.action_StartAll->setEnabled( paused > 0 );
1044
1080
void
1045
1081
TrMainWindow :: newTorrent( )
1046
1082
{
1047
 
    MakeDialog * d = new MakeDialog( mySession, this );
1048
 
    d->show( );
 
1083
    MakeDialog * dialog = new MakeDialog( mySession, this );
 
1084
    dialog->show( );
1049
1085
}
1050
1086
 
1051
1087
void
1060
1096
        myFileDialog->setFileMode( QFileDialog::ExistingFiles );
1061
1097
 
1062
1098
 
1063
 
        QCheckBox * button = new QCheckBox( tr( "Display &options dialog" ) );
 
1099
        QCheckBox * button = new QCheckBox( tr( "Show &options dialog" ) );
1064
1100
        button->setChecked( myPrefs.getBool( Prefs::OPTIONS_PROMPT ) );
1065
1101
        QGridLayout * layout = dynamic_cast<QGridLayout*>(myFileDialog->layout());
1066
1102
        layout->addWidget( button, layout->rowCount( ), 0, 1, -1, Qt::AlignLeft );
1067
1103
        myFileDialogOptionsCheck = button;
1068
1104
 
1069
 
        connect( myFileDialog, SIGNAL(filesSelected(const QStringList&)), this, SLOT(addTorrents(const QStringList&)));
 
1105
        connect( myFileDialog, SIGNAL(filesSelected(const QStringList&)),
 
1106
                 this, SLOT(addTorrents(const QStringList&)));
1070
1107
    }
1071
1108
 
1072
1109
    myFileDialog->show( );
1073
1110
}
1074
1111
 
1075
1112
void
 
1113
TrMainWindow :: openURL( )
 
1114
{
 
1115
    bool ok;
 
1116
    const QString key = QInputDialog::getText( this,
 
1117
                                               tr( "Add URL or Magnet Link" ),
 
1118
                                               tr( "Add URL or Magnet Link" ),
 
1119
                                               QLineEdit::Normal,
 
1120
                                               QString( ),
 
1121
                                               &ok );
 
1122
    if( ok && !key.isEmpty( ) )
 
1123
        mySession.addTorrent( key );
 
1124
}
 
1125
 
 
1126
void
1076
1127
TrMainWindow :: addTorrents( const QStringList& filenames )
1077
1128
{
1078
1129
    foreach( const QString& filename, filenames )