20
20
* You should have received a copy of the GNU General Public License *
21
21
* along with this program; if not, write to the *
22
* Free Software Foundation, 51 Franklin Street, Suite 500, Boston, *
22
* Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
23
23
* MA 02110-1335, USA *
24
24
***************************************************************************/
30
// application specific includes
31
#include "smb4kpreviewer_p.h"
32
#include "smb4knotification.h"
33
#include "smb4khost.h"
34
#include "smb4kshare.h"
35
#include "smb4kglobal.h"
36
#include "smb4ksettings.h"
37
#include "smb4kcustomoptionsmanager.h"
38
#include "smb4kcustomoptions.h"
28
#include <QGridLayout>
41
#include <QtCore/QTimer>
42
#include <QtCore/QDateTime>
43
#include <QtCore/QLatin1String>
44
#include <QtGui/QGridLayout>
32
47
#include <kdebug.h>
113
118
emit aboutToStart( m_share, m_url );
115
120
// Get the path that has to be listed.
116
QString path = m_url.toString( QUrl::RemoveScheme|QUrl::RemoveUserInfo|QUrl::RemovePort );
121
QString path = m_url.path();
118
123
if ( !m_share->isHomesShare() )
120
path.remove( m_share->unc(), Qt::CaseInsensitive );
125
path.remove( m_share->shareName(), Qt::CaseInsensitive );
124
path.remove( m_share->homeUNC(), Qt::CaseInsensitive );
129
path.remove( m_share->login(), Qt::CaseInsensitive );
127
132
// Compile the command line arguments
128
133
QStringList arguments;
337
342
m_proc->setEnv( "PASSWD", m_share->password(), true );
338
343
m_proc->setShellCommand( arguments.join( " " ) );
340
connect( m_proc, SIGNAL( readyReadStandardOutput() ), SLOT( slotReadStandardOutput() ) );
341
connect( m_proc, SIGNAL( readyReadStandardError() ), SLOT( slotReadStandardError() ) );
342
connect( m_proc, SIGNAL( finished( int, QProcess::ExitStatus ) ), SLOT( slotProcessFinished( int, QProcess::ExitStatus ) ) );
345
connect( m_proc, SIGNAL(readyReadStandardOutput()), SLOT(slotReadStandardOutput()) );
346
connect( m_proc, SIGNAL(readyReadStandardError()), SLOT(slotReadStandardError()) );
347
connect( m_proc, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(slotProcessFinished(int,QProcess::ExitStatus)) );
348
353
void Smb4KPreviewJob::slotReadStandardOutput()
350
QStringList list = QString::fromUtf8( m_proc->readAllStandardOutput(), -1 ).split( "\n", QString::SkipEmptyParts );
353
foreach ( const QString &line, list )
355
if ( line.contains( "blocks of size" ) || line.contains( "Domain=[" ) )
359
else if ( line.contains( "NT_STATUS_ACCESS_DENIED", Qt::CaseSensitive ) ||
360
line.contains( "NT_STATUS_LOGON_FAILURE", Qt::CaseSensitive ) )
362
// This might happen if a directory cannot be accessed due to missing
364
emit authError( this );
369
QString entry = line;
371
QString left = entry.trimmed().section( " ", 0, -2 ).trimmed();
372
QString right = entry.remove( left );
374
QString name = left.section( " ", 0, -2 ).trimmed().isEmpty() ?
376
left.section( " ", 0, -2 ).trimmed();
378
QString dir_string = left.right( 3 ).trimmed();
379
bool is_dir = (!dir_string.isEmpty() && dir_string.contains( "D" ));
381
QString tmp_size = right.trimmed().section( " ", 0, 0 ).trimmed();
384
if ( tmp_size[0].isLetter() )
386
size = right.trimmed().section( " ", 1, 1 ).trimmed();
393
QString date = QDateTime::fromString( right.section( QString( " %1 " ).arg( size ), 1, 1 ).trimmed() ).toString();
395
if ( !name.isEmpty() )
401
if ( name.startsWith( "." ) &&
402
(QString::compare( name, "." ) != 0 && QString::compare( name, ".." ) != 0) )
404
item.first = HiddenDirectoryItem;
408
item.first = DirectoryItem;
413
if ( name.startsWith( "." ) )
415
item.first = HiddenFileItem;
419
item.first = FileItem;
423
item.second["name"] = name;
424
item.second["size"] = size;
425
item.second["date"] = date;
355
QString stdout = QString::fromUtf8( m_proc->readAllStandardOutput(), -1 );
357
if ( stdout.contains( "NT_STATUS_ACCESS_DENIED", Qt::CaseSensitive ) ||
358
stdout.contains( "NT_STATUS_LOGON_FAILURE", Qt::CaseSensitive ) )
360
// This might happen if a directory cannot be accessed due to missing
362
emit authError( this );
366
QStringList list = stdout.split( '\n', QString::SkipEmptyParts );
369
foreach ( const QString &line, list )
371
if ( line.contains( "blocks of size" ) || line.contains( "Domain=[" ) )
377
QString entry = line;
379
QString left = entry.trimmed().section( " ", 0, -2 ).trimmed();
380
QString right = entry.remove( left );
382
QString name = left.section( " ", 0, -2 ).trimmed().isEmpty() ?
384
left.section( " ", 0, -2 ).trimmed();
386
QString dir_string = left.right( 3 ).trimmed();
387
bool is_dir = (!dir_string.isEmpty() && dir_string.contains( "D" ));
389
QString tmp_size = right.trimmed().section( " ", 0, 0 ).trimmed();
392
if ( tmp_size[0].isLetter() )
394
size = right.trimmed().section( " ", 1, 1 ).trimmed();
401
QString date = QDateTime::fromString( right.section( QString( " %1 " ).arg( size ), 1, 1 ).trimmed() ).toString();
403
if ( !name.isEmpty() )
409
if ( name.startsWith( '.' ) &&
410
(QString::compare( name, "." ) != 0 && QString::compare( name, ".." ) != 0) )
412
item.first = HiddenDirectoryItem;
416
item.first = DirectoryItem;
421
if ( name.startsWith( '.' ) )
423
item.first = HiddenFileItem;
427
item.first = FileItem;
431
item.second["name"] = name;
432
item.second["size"] = size;
433
item.second["date"] = date;
444
emit preview( m_url, items );
436
emit preview( m_url, items );
564
connect( this, SIGNAL( closeClicked() ),
565
this, SLOT( slotCloseClicked() ) );
573
connect( this, SIGNAL(closeClicked()),
574
this, SLOT(slotCloseClicked()) );
567
576
setMinimumWidth( sizeHint().width() > 350 ? sizeHint().width() : 350 );
569
578
KConfigGroup group( Smb4KSettings::self()->config(), "PreviewDialog" );
570
579
restoreDialogSize( group );
572
QTimer::singleShot( 0, this, SLOT( slotRequestPreview() ) );
581
QTimer::singleShot( 0, this, SLOT(slotRequestPreview()) );
630
639
layout->addWidget( m_view, 0, 0, 0 );
631
640
layout->addWidget( toolbar, 1, 0, 0 );
633
connect( toolbar, SIGNAL( actionTriggered( QAction * ) ),
634
this, SLOT( slotActionTriggered( QAction * ) ) );
636
connect( m_combo, SIGNAL( activated( const QString & ) ),
637
this, SLOT( slotItemActivated( const QString & ) ) );
639
connect( m_view, SIGNAL( executed( QListWidgetItem * ) ),
640
this, SLOT( slotItemExecuted( QListWidgetItem * ) ) );
642
connect( KGlobalSettings::self(), SIGNAL( iconChanged( int ) ),
643
this, SLOT( slotIconSizeChanged( int ) ) );
642
connect( toolbar, SIGNAL(actionTriggered(QAction*)),
643
this, SLOT(slotActionTriggered(QAction*)) );
645
connect( m_combo, SIGNAL(activated(QString)),
646
this, SLOT(slotItemActivated(QString)) );
648
connect( m_view, SIGNAL(executed(QListWidgetItem*)),
649
this, SLOT(slotItemExecuted(QListWidgetItem*)) );
651
connect( KGlobalSettings::self(), SIGNAL(iconChanged(int)),
652
this, SLOT(slotIconSizeChanged(int)) );
790
799
else if ( kaction == m_up )
792
if ( QString::compare( m_share->unc(), m_url.toString( QUrl::RemoveScheme|QUrl::RemoveUserInfo|QUrl::RemovePort ), Qt::CaseInsensitive ) != 0 )
801
QString test = QString("//%1%2%3")
803
.arg(m_url.path().startsWith('/') ? "" : "/")
804
.arg(m_url.path(KUrl::RemoveTrailingSlash));
806
if ( QString::compare( m_share->unc(), test, Qt::CaseInsensitive ) != 0 )
794
808
// Clear the history
795
809
m_history.clear();
797
811
// Adjust the path
812
// FIXME: Use KUrl::upUrl() here when we have found to adjust
798
814
QString path = m_url.path();
799
m_url.setPath( path.section( "/", 0, -2 ) );
815
m_url.setPath( path.section( '/', 0, -2 ) );
801
817
// Request the preview
802
818
slotRequestPreview();
934
955
m_forward->setEnabled( enable_forward );
936
957
// Enable/disable the up action.
937
bool enable_up = (QString::compare( m_share->unc(),
938
m_url.toString( QUrl::RemoveScheme|QUrl::RemoveUserInfo|QUrl::RemovePort ),
939
Qt::CaseInsensitive ) != 0);
958
QString test = QString("//%1%2%3")
960
.arg(m_url.path().startsWith('/') ? "" : "/")
961
.arg(m_url.path(KUrl::RemoveTrailingSlash));
962
bool enable_up = (QString::compare( m_share->unc(), test, Qt::CaseInsensitive ) != 0);
940
963
m_up->setEnabled( enable_up );
944
void Smb4KPreviewDialog::slotAboutToStart( Smb4KShare *share, const QUrl &url )
967
void Smb4KPreviewDialog::slotAboutToStart( Smb4KShare *share, const KUrl &url )
946
969
if ( share == m_share && url == m_url )