File indexing completed on 2024-05-19 04:49:16

0001 /****************************************************************************************
0002  * Copyright (c) 2012 Ryan McCoskrie <ryan.mccoskrie@gmail.com>                         *
0003  * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
0004  * Copyright (c) 2010 Casey Link <unnamedrambler@gmail.com>                             *
0005  *                                                                                      *
0006  * This program is free software; you can redistribute it and/or modify it under        *
0007  * the terms of the GNU General Public License as published by the Free Software        *
0008  * Foundation; either version 2 of the License, or (at your option) any later           *
0009  * version.                                                                             *
0010  *                                                                                      *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0013  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0014  *                                                                                      *
0015  * You should have received a copy of the GNU General Public License along with         *
0016  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0017  ****************************************************************************************/
0018 
0019 #include "CollectionLocationDelegateImpl.h"
0020 
0021 #include "core/logger/Logger.h"
0022 #include "core/collections/CollectionLocation.h"
0023 #include "core/support/Components.h"
0024 #include "transcoding/TranscodingAssistantDialog.h"
0025 
0026 #include <KLocalizedString>
0027 #include <KMessageBox>
0028 
0029 using namespace Collections;
0030 
0031 bool
0032 CollectionLocationDelegateImpl::reallyDelete( CollectionLocation *loc, const Meta::TrackList &tracks ) const
0033 {
0034     QStringList files = trackList( tracks );
0035     const QString text( i18ncp( "@info",
0036         "Do you really want to delete this track? It will be removed from %2 and from underlying storage medium.",
0037         "Do you really want to delete these %1 tracks? They will be removed from %2 and from underlying storage medium.",
0038          tracks.count(), loc->prettyLocation()) );
0039     int ret = KMessageBox::warningContinueCancelList(nullptr, text, files,
0040         i18nc( "@title:window", "Confirm Delete" ), KStandardGuiItem::del() );
0041     return ret == KMessageBox::Continue;
0042 }
0043 
0044 bool
0045 CollectionLocationDelegateImpl::reallyTrash( CollectionLocation *loc, const Meta::TrackList &tracks ) const
0046 {
0047     QStringList files = trackList( tracks );
0048     const QString text( i18ncp( "@info",
0049         "Do you really want to move this track to the trash? It will be removed from %2.",
0050         "Do you really want to move these %1 tracks to the trash? They will be removed from %2.",
0051         tracks.count(), loc->prettyLocation() ) );
0052     int ret = KMessageBox::warningContinueCancelList( nullptr, text, files,
0053         i18nc( "@title:window", "Confirm Move to Trash" ), KStandardGuiItem::remove() );
0054     return ret == KMessageBox::Continue;
0055 }
0056 
0057 bool
0058 CollectionLocationDelegateImpl::reallyMove( CollectionLocation *loc, const Meta::TrackList &tracks ) const
0059 {
0060     Q_UNUSED( loc )
0061     QStringList files = trackList( tracks );
0062     const QString text( i18ncp( "@info",
0063         "Do you really want to move this track? It will be renamed and the original deleted.",
0064         "Do you really want to move these %1 tracks? They will be renamed and the originals deleted.",
0065         tracks.count() ) );
0066     int ret = KMessageBox::warningContinueCancelList( nullptr, text, files,
0067         i18nc( "@title:window", "Move Files" ), KGuiItem( i18nc( "rename files button", "&Rename" ), QStringLiteral("go-jump") ) );
0068     return ret == KMessageBox::Continue;
0069 }
0070 
0071 void
0072 CollectionLocationDelegateImpl::errorDeleting( CollectionLocation *loc, const Meta::TrackList &tracks ) const
0073 {
0074     Q_UNUSED( loc )
0075     QStringList files = trackList( tracks );
0076     const QString text( i18ncp( "@info",
0077         "There was a problem and this track could not be removed. Make sure the directory is writable.",
0078         "There was a problem and %1 tracks could not be removed. Make sure the directory is writable.",
0079         files.count() ) );
0080     KMessageBox::informationList( nullptr, text, files, i18n( "Unable to remove tracks") );
0081 }
0082 
0083 void
0084 CollectionLocationDelegateImpl::notWriteable( CollectionLocation *loc ) const
0085 {
0086     Q_UNUSED( loc )
0087     Amarok::Logger::longMessage(
0088             i18n( "The collection does not have enough free space available or is not writable." ),
0089             Amarok::Logger::Error );
0090 }
0091 
0092 bool
0093 CollectionLocationDelegateImpl::deleteEmptyDirs( CollectionLocation *loc ) const
0094 {
0095     const QString text( i18n( "Do you want to remove empty folders?" ) );
0096     const QString caption( i18n( "Remove empty folders?" ) );
0097     int result = KMessageBox::questionYesNo( nullptr, text, caption, KStandardGuiItem::yes(),
0098         KStandardGuiItem::no(), QString( "Delete empty dirs from " + loc->prettyLocation() ) );
0099     return result == KMessageBox::Yes;
0100 }
0101 
0102 Transcoding::Configuration
0103 CollectionLocationDelegateImpl::transcode( const QStringList &playableFileTypes,
0104                                            bool *remember, OperationType operation,
0105                                            const QString &destCollectionName,
0106                                            const Transcoding::Configuration &prevConfiguration ) const
0107 {
0108     Transcoding::AssistantDialog dialog( playableFileTypes, remember != nullptr, operation,
0109                                          destCollectionName, prevConfiguration );
0110     if( dialog.exec() )
0111     {
0112         if( remember )
0113             *remember = dialog.shouldSave();
0114         return dialog.configuration();
0115     }
0116     return Transcoding::Configuration( Transcoding::INVALID );
0117 }
0118 
0119 QStringList
0120 CollectionLocationDelegateImpl::trackList( const Meta::TrackList &tracks ) const
0121 {
0122     QStringList trackList;
0123     foreach( Meta::TrackPtr track, tracks )
0124     {
0125         QString url = track->prettyUrl();
0126         Meta::ArtistPtr artist = track->artist();
0127         QString artistName = artist ? artist->name() : QString();
0128         QString trackName = track->name();
0129 
0130         QString str;
0131         // Add track and artist name if available
0132         if( !trackName.isEmpty() && !artistName.isEmpty() )
0133             str = i18nc( "%1 is track url, %2 track title, %3 track artist",
0134                          "%1 (%2 by %3)", url, trackName, artistName );
0135         else if( !trackName.isEmpty() )
0136             str = i18nc( "%1 is track url, %2 track name", "%1 (%2)", url, trackName );
0137         else if( !artistName.isEmpty() )
0138             str = i18nc( "%1 is track url, %2 artist name", "%1 (by %2)", url, artistName );
0139         else
0140             str = url;
0141 
0142         trackList << str;
0143     }
0144 
0145     return trackList;
0146 }