2 kopetefileconfirmdialog.cpp
4 Copyright (c) 2003-2004 by Olivier Goffart <ogoffart @ kde.org>
6 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU Lesser General Public *
12 * License as published by the Free Software Foundation; either *
13 * version 2 of the License, or (at your option) any later version. *
15 *************************************************************************
19 #include <QCloseEvent>
21 #include <klineedit.h>
24 #include <kfiledialog.h>
25 #include <kpushbutton.h>
26 #include <kmessagebox.h>
28 //#include "kopetetransfermanager.h"
29 #include "fileconfirmbase.h"
30 #include "kopetefileconfirmdialog.h"
32 #include "kopetemetacontact.h"
33 #include "kopetecontact.h"
35 KopeteFileConfirmDialog::KopeteFileConfirmDialog(const Kopete::FileTransferInfo
&info
,const QString
& description
,QWidget
*parent
, const char *name
)
36 : KDialogBase( parent
, name
, false, i18n( "A User Would Like to Send You a File" ),
37 KDialogBase::User1
| KDialogBase::User2
, KDialogBase::User1
, true, i18n( "&Refuse" ), i18n( "&Accept" ) ),
40 setAttribute( Qt::WA_DeleteOnClose
);
43 m_view
=new FileConfirmBase(this, "FileConfirmView");
44 m_view
->m_from
->setText( info
.contact()->metaContact()->displayName() + QString::fromLatin1( " <" ) +
45 info
.contact()->contactId() + QString::fromLatin1( "> " ) );
46 m_view
->m_size
->setText( KGlobal::locale()->formatNumber( long( info
.size() ) ) );
47 m_view
->m_description
->setText( description
);
48 m_view
->m_filename
->setText( info
.file() );
50 KGlobal::config()->setGroup("File Transfer");
51 const QString defaultPath
=KGlobal::config()->readEntry("defaultPath" , QDir::homePath() );
52 m_view
->m_saveto
->setText(defaultPath
+ QString::fromLatin1( "/" ) + info
.file() );
54 setMainWidget(m_view
);
56 connect(m_view
->cmdBrowse
, SIGNAL(pressed()), this, SLOT(slotBrowsePressed()));
59 KopeteFileConfirmDialog::~KopeteFileConfirmDialog()
63 void KopeteFileConfirmDialog::slotBrowsePressed()
65 QString saveFileName
= KFileDialog::getSaveFileName( m_view
->m_saveto
->text(), QString::fromLatin1( "*" ), 0L , i18n( "File Transfer" ) );
66 if ( !saveFileName
.isNull())
68 m_view
->m_saveto
->setText(saveFileName
);
72 void KopeteFileConfirmDialog::slotUser2()
75 KURL
url(m_view
->m_saveto
->text());
76 if(url
.isValid() && url
.isLocalFile() )
78 const QString directory
=url
.directory();
79 if(!directory
.isEmpty())
81 KGlobal::config()->setGroup("File Transfer");
82 KGlobal::config()->writeEntry("defaultPath" , directory
);
85 if(QFile(m_view
->m_saveto
->text()).exists())
87 int ret
=KMessageBox::warningContinueCancel(this, i18n("The file '%1' already exists.\nDo you want to overwrite it ?").arg(m_view
->m_saveto
->text()) ,
88 i18n("Overwrite File") , KStdGuiItem::save());
89 if(ret
==KMessageBox::Cancel
)
93 emit
accepted(m_info
,m_view
->m_saveto
->text());
97 KMessageBox::queuedMessageBox (this, KMessageBox::Sorry
, i18n("You must provide a valid local filename") );
100 void KopeteFileConfirmDialog::slotUser1()
103 emit
refused(m_info
);
107 void KopeteFileConfirmDialog::closeEvent( QCloseEvent
*e
)
112 emit
refused(m_info
);
114 KDialogBase::closeEvent(e
);
117 #include "kopetefileconfirmdialog.moc"