Framework for looking up contacts directly in nepomuk in addition to going through...
[kdepim.git] / messageviewer / attachmentdialog.cpp
blobbaed5d1f0585a29a2bd5173474ecb3852d125d4d
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 2009 Martin Koller <kollix@aon.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <config-messageviewer.h>
22 #include <attachmentdialog.h>
24 #include <kdialog.h>
25 #include <kmessagebox.h>
26 #include <klocale.h>
28 using namespace MessageViewer;
30 //---------------------------------------------------------------------
32 AttachmentDialog::AttachmentDialog( QWidget *parent, const QString &filenameText,
33 const QString &application, const QString &dontAskAgainName )
34 : dontAskName( dontAskAgainName )
36 text = i18n( "Open attachment '%1'?\n"
37 "Note that opening an attachment may compromise "
38 "your system's security.",
39 filenameText );
41 dialog = new KDialog( parent );
42 dialog->setCaption( i18n("Open Attachment?") );
43 dialog->setObjectName( "attachmentSaveOpen" );
45 if ( application.isEmpty() )
46 dialog->setButtons( KDialog::User3 | KDialog::User1 | KDialog::Cancel );
47 else {
48 dialog->setButtons( KDialog::User3 | KDialog::User2 | KDialog::User1 | KDialog::Cancel );
49 dialog->setButtonText( KDialog::User2, i18n("&Open with '%1'", application ) );
52 dialog->setButtonGuiItem( KDialog::User3, KStandardGuiItem::saveAs() );
53 dialog->setButtonText( KDialog::User1, i18n("&Open With...") );
54 dialog->setDefaultButton( KDialog::User3 );
56 connect( dialog, SIGNAL(user3Clicked()), this, SLOT(saveClicked()) );
57 connect( dialog, SIGNAL(user2Clicked()), this, SLOT(openClicked()) );
58 connect( dialog, SIGNAL(user1Clicked()), this, SLOT(openWithClicked()) );
61 //---------------------------------------------------------------------
63 int AttachmentDialog::exec()
65 KConfigGroup cg( KGlobal::config().data(), "Notification Messages" );
66 if ( cg.hasKey( dontAskName ) )
67 return cg.readEntry( dontAskName, int(0) );
69 bool again = false;
70 const int ret =
71 KMessageBox::createKMessageBox( dialog, QMessageBox::Question, text, QStringList(),
72 i18n( "Do not ask again" ), &again, 0 );
74 if ( ret == QDialog::Rejected )
75 return Cancel;
76 else {
77 if ( again ) {
78 KConfigGroup::WriteConfigFlags flags = KConfig::Persistent;
79 KConfigGroup cg( KGlobal::config().data(), "Notification Messages" );
80 cg.writeEntry( dontAskName, ret, flags );
81 cg.sync();
84 return ret;
88 //---------------------------------------------------------------------
90 void AttachmentDialog::saveClicked()
92 dialog->done( Save );
95 //---------------------------------------------------------------------
97 void AttachmentDialog::openClicked()
99 dialog->done( Open );
102 //---------------------------------------------------------------------
104 void AttachmentDialog::openWithClicked()
106 dialog->done( OpenWith );
109 //---------------------------------------------------------------------
111 #include "attachmentdialog.moc"