1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 03:40:16 +02:00

Add options for controlling scanning time and mode

This commit is contained in:
Jeff Mitchell
2011-05-21 14:29:47 -04:00
parent 345d6858ff
commit 0ea35a9b3e
6 changed files with 185 additions and 23 deletions

View File

@@ -177,7 +177,6 @@ TomahawkSettings::hasScannerPaths() const
TomahawkSettings::ScannerMode TomahawkSettings::ScannerMode
TomahawkSettings::scannerMode() const TomahawkSettings::scannerMode() const
{ {
//FIXME: Default to directories?
return (TomahawkSettings::ScannerMode) value( "scanner-mode", TomahawkSettings::Files ).toInt(); return (TomahawkSettings::ScannerMode) value( "scanner-mode", TomahawkSettings::Files ).toInt();
} }
@@ -189,6 +188,20 @@ TomahawkSettings::setScannerMode( ScannerMode mode )
} }
uint
TomahawkSettings::scannerTime() const
{
return value( "scannerTime", 60 ).toUInt();
}
void
TomahawkSettings::setScannerTime( uint time )
{
setValue( "scannerTime", time );
}
bool bool
TomahawkSettings::watchForChanges() const TomahawkSettings::watchForChanges() const
{ {

View File

@@ -47,7 +47,9 @@ public:
bool hasScannerPaths() const; bool hasScannerPaths() const;
ScannerMode scannerMode() const; ScannerMode scannerMode() const;
void setScannerMode( ScannerMode mode ); void setScannerMode( ScannerMode mode );
uint scannerTime() const;
void setScannerTime( uint time );
bool watchForChanges() const; bool watchForChanges() const;
void setWatchForChanges( bool watch ); void setWatchForChanges( bool watch );

View File

@@ -50,15 +50,11 @@ ScanManager::ScanManager( QObject* parent )
m_scanTimer = new QTimer( this ); m_scanTimer = new QTimer( this );
m_scanTimer->setSingleShot( false ); m_scanTimer->setSingleShot( false );
m_scanTimer->setInterval( 120000 ); m_scanTimer->setInterval( TomahawkSettings::instance()->scannerTime() * 1000 );
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) ); connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
connect( m_scanTimer, SIGNAL( timeout() ), SLOT( scanTimerTimeout() ) ); connect( m_scanTimer, SIGNAL( timeout() ), SLOT( scanTimerTimeout() ) );
// FIXME: Disable this until we find something nondeprecated and working (e.g. not QFileSystemWatcher)
TomahawkSettings::instance()->setWatchForChanges( true );
TomahawkSettings::instance()->setScannerMode( TomahawkSettings::Files );
if ( TomahawkSettings::instance()->hasScannerPaths() ) if ( TomahawkSettings::instance()->hasScannerPaths() )
{ {
m_currScannerPaths = TomahawkSettings::instance()->scannerPaths(); m_currScannerPaths = TomahawkSettings::instance()->scannerPaths();
@@ -105,6 +101,8 @@ ScanManager::onSettingsChanged()
{ {
if ( !TomahawkSettings::instance()->watchForChanges() && m_scanTimer->isActive() ) if ( !TomahawkSettings::instance()->watchForChanges() && m_scanTimer->isActive() )
m_scanTimer->stop(); m_scanTimer->stop();
m_scanTimer->setInterval( TomahawkSettings::instance()->scannerTime() * 1000 );
if ( TomahawkSettings::instance()->hasScannerPaths() && if ( TomahawkSettings::instance()->hasScannerPaths() &&
m_currScannerPaths != TomahawkSettings::instance()->scannerPaths() ) m_currScannerPaths != TomahawkSettings::instance()->scannerPaths() )

View File

@@ -115,11 +115,26 @@ SettingsDialog::SettingsDialog( QWidget *parent )
ui->lineEditMusicPath_2->setText( QDesktopServices::storageLocation( QDesktopServices::MusicLocation ) ); ui->lineEditMusicPath_2->setText( QDesktopServices::storageLocation( QDesktopServices::MusicLocation ) );
} }
// WATCH CHANGES
// FIXME: QFileSystemWatcher is broken (as we know) and deprecated. Find another way.
ui->checkBoxWatchForChanges->setChecked( s->watchForChanges() ); ui->checkBoxWatchForChanges->setChecked( s->watchForChanges() );
ui->checkBoxWatchForChanges->setVisible( false ); ui->scannerTimeSpinBox->setValue( s->scannerTime() );
if ( s->scannerMode() == TomahawkSettings::Files )
ui->scannerFileModeButton->setChecked( true );
else
ui->scannerDirModeButton->setChecked( false );
connect( ui->checkBoxWatchForChanges, SIGNAL( clicked( bool ) ), SLOT( updateScanOptionsView() ) );
connect( ui->scannerDirModeButton, SIGNAL( clicked( bool ) ), SLOT( updateScanOptionsView() ) );
connect( ui->scannerFileModeButton, SIGNAL( clicked( bool ) ), SLOT( updateScanOptionsView() ) );
if ( s->scannerMode() == TomahawkSettings::Files )
{
ui->scanInformationLabel->setText( "Files mode uses the changed time of every file to determine if the file has\nchanged. This can be more processor, disk, and network-intensive, especially\nfor files over a network connection. This mode is recommended, but switch\nto Directory Mode or raise the time between scans if you encounter trouble." );
ui->scannerFileModeButton->setChecked( true );
}
else
{
ui->scanInformationLabel->setText( "Directory mode mode uses the changed time of collection directories to\ndetermine if files have changed. This is less processor, disk, and \nnetwork-intensive when simply running checks, so may be better for\nfiles over a network connection. However, it will only pick up changes\nif a file has been added to or removed from a directory, and scans\nentire directories at once (so is not good for very flat collections)." );
ui->scannerDirModeButton->setChecked( true );
}
// LAST FM // LAST FM
ui->checkBoxEnableLastfm->setChecked( s->scrobblingEnabled() ); ui->checkBoxEnableLastfm->setChecked( s->scrobblingEnabled() );
ui->lineEditLastfmUsername->setText( s->lastFmUsername() ); ui->lineEditLastfmUsername->setText( s->lastFmUsername() );
@@ -164,6 +179,8 @@ SettingsDialog::~SettingsDialog()
s->setScannerPaths( QStringList( ui->lineEditMusicPath_2->text() ) ); s->setScannerPaths( QStringList( ui->lineEditMusicPath_2->text() ) );
s->setWatchForChanges( ui->checkBoxWatchForChanges->isChecked() ); s->setWatchForChanges( ui->checkBoxWatchForChanges->isChecked() );
s->setScannerTime( ui->scannerTimeSpinBox->value() );
s->setScannerMode( ui->scannerFileModeButton->isChecked() ? TomahawkSettings::Files : TomahawkSettings::Dirs );
s->setScrobblingEnabled( ui->checkBoxEnableLastfm->isChecked() ); s->setScrobblingEnabled( ui->checkBoxEnableLastfm->isChecked() );
s->setLastFmUsername( ui->lineEditLastfmUsername->text() ); s->setLastFmUsername( ui->lineEditLastfmUsername->text() );
@@ -180,6 +197,7 @@ SettingsDialog::~SettingsDialog()
delete ui; delete ui;
} }
void void
SettingsDialog::createIcons() SettingsDialog::createIcons()
{ {
@@ -326,6 +344,38 @@ SettingsDialog::toggleUpnp( bool preferStaticEnabled )
} }
void
SettingsDialog::updateScanOptionsView()
{
if ( ui->checkBoxWatchForChanges->isChecked() )
{
ui->scanTimeLabel->show();
ui->scannerTimeSpinBox->show();
ui->scannerDirModeButton->show();
ui->scannerFileModeButton->show();
ui->scanInformationLabel->show();
if ( sender() == ui->scannerFileModeButton )
{
ui->scanInformationLabel->setText( "Files mode uses the changed time of every file to determine if the file has\nchanged. This can be more processor, disk, and network-intensive, especially\nfor files over a network connection. This mode is recommended, but switch\nto Directory Mode or raise the time between scans if you encounter trouble." );
ui->scannerFileModeButton->setChecked( true );
}
else
{
ui->scanInformationLabel->setText( "Directory mode mode uses the changed time of collection directories to\ndetermine if files have changed. This is less processor, disk, and \nnetwork-intensive when simply running checks, so may be better for\nfiles over a network connection. However, it will only pick up changes\nif a file has been added to or removed from a directory, and scans\nentire directories at once (so is not good for very flat collections)." );
ui->scannerDirModeButton->setChecked( true );
}
}
else
{
ui->scanTimeLabel->hide();
ui->scannerTimeSpinBox->hide();
ui->scannerDirModeButton->hide();
ui->scannerFileModeButton->hide();
ui->scanInformationLabel->hide();
}
}
void void
SettingsDialog::testLastFmLogin() SettingsDialog::testLastFmLogin()
{ {

View File

@@ -87,6 +87,8 @@ private slots:
void sipPluginDeleted( bool ); void sipPluginDeleted( bool );
void sipPluginRowDeleted( bool ); void sipPluginRowDeleted( bool );
void updateScanOptionsView();
// dialog slots // dialog slots
void resolverConfigClosed( int value ); void resolverConfigClosed( int value );
void sipConfigClosed( int value ); void sipConfigClosed( int value );

View File

@@ -100,7 +100,7 @@
<item> <item>
<widget class="QStackedWidget" name="stackedWidget"> <widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="accountsPage"> <widget class="QWidget" name="accountsPage">
<layout class="QVBoxLayout" name="verticalLayout_11"> <layout class="QVBoxLayout" name="verticalLayout_11">
@@ -250,21 +250,118 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="scanTimeLabel">
<property name="text">
<string>Time between scans, in seconds:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="scannerTimeSpinBox">
<property name="minimum">
<number>60</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QRadioButton" name="scannerFileModeButton">
<property name="text">
<string>Files Mode</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="scannerDirModeButton">
<property name="text">
<string>Directory Mode</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="verticalSpacer"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="orientation"> <item>
<enum>Qt::Vertical</enum> <spacer name="verticalSpacer_9">
</property> <property name="orientation">
<property name="sizeHint" stdset="0"> <enum>Qt::Vertical</enum>
<size> </property>
<width>20</width> <property name="sizeType">
<height>40</height> <enum>QSizePolicy::Minimum</enum>
</size> </property>
</property> <property name="sizeHint" stdset="0">
</spacer> <size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="scanInformationLabel">
<property name="text">
<string>Directory mode mode uses the changed time of collection directories to
determine if files have changed. This is less processor, disk, and
network-intensive when simply running checks, so may be better for
files over a network connection. However, it will only pick up changes
if a file has been added to or removed from a directory, and scans
entire directories at once (so is not good for very flat collections).</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>