File indexing completed on 2024-04-21 15:42:51

0001 /***************************************************************************
0002     Private helper classes for the wallet manager of Smb4K.
0003                              -------------------
0004     begin                : Mo Dez 31 2012
0005     copyright            : (C) 2012-2019 by Alexander Reinholdt
0006     email                : alexander.reinholdt@kdemail.net
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *   This program is free software; you can redistribute it and/or modify  *
0011  *   it under the terms of the GNU General Public License as published by  *
0012  *   the Free Software Foundation; either version 2 of the License, or     *
0013  *   (at your option) any later version.                                   *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful, but   *
0016  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
0018  *   General Public License for more details.                              *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program; if not, write to the                         *
0022  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
0023  *   MA 02110-1335, USA                                                    *
0024  ***************************************************************************/
0025 
0026 // application specific includes
0027 #include "smb4kwalletmanager_p.h"
0028 #include "smb4khost.h"
0029 #include "smb4kshare.h"
0030 #include "smb4khomesshareshandler.h"
0031 #include "smb4kglobal.h"
0032 
0033 // Qt includes
0034 #include <QDebug>
0035 
0036 // KDE includes
0037 #define TRANSLATION_DOMAIN "smb4k-core"
0038 #include <KI18n/KLocalizedString>
0039 
0040 using namespace Smb4KGlobal;
0041 
0042 
0043 Smb4KPasswordDialog::Smb4KPasswordDialog(const NetworkItemPtr &networkItem, const QMap<QString,QString> &knownLogins, QWidget* parent)
0044 : KPasswordDialog(parent, KPasswordDialog::ShowUsernameLine)
0045 {
0046   m_item = networkItem;
0047   
0048   switch (m_item->type())
0049   {
0050     case Host:
0051     {
0052       HostPtr host = m_item.staticCast<Smb4KHost>();
0053 
0054       if (host)
0055       {
0056         setUsername(host->login());
0057         setPassword(host->password());
0058         setPrompt(i18n("<qt>Please enter a username and a password for the host <b>%1</b>.</qt>", host->hostName()));
0059       }
0060 
0061       break;
0062     }
0063     case Share:
0064     {
0065       SharePtr share = m_item.staticCast<Smb4KShare>();
0066 
0067       if (share)
0068       {
0069         // Enter authentication information into the dialog
0070         if (!knownLogins.isEmpty())
0071         {
0072           setKnownLogins(knownLogins);
0073         }
0074         else
0075         {
0076           setUsername(share->login());
0077           setPassword(share->password());
0078         }
0079 
0080         if (!share->isHomesShare())
0081         {
0082           setPrompt(i18n("<qt>Please enter a username and a password for the share <b>%1</b>.</qt>", share->displayString()));
0083         }
0084         else
0085         {
0086           setPrompt(i18n("<qt>Please enter a username and a password for the share <b>%1 on %2</b>.</qt>", share->displayString(true)));
0087         }
0088       }
0089 
0090       break;
0091     }
0092     default:
0093     {
0094       break;
0095     }
0096   }
0097 
0098   connect(this, SIGNAL(gotUsernameAndPassword(QString,QString,bool)), SLOT(slotGotUsernameAndPassword(QString,QString,bool)));
0099 }
0100 
0101 
0102 Smb4KPasswordDialog::~Smb4KPasswordDialog()
0103 {
0104 }
0105 
0106 
0107 void Smb4KPasswordDialog::slotGotUsernameAndPassword(const QString &user, const QString &pass, bool /*keep*/)
0108 {
0109   switch (m_item->type())
0110   {
0111     case Host:
0112     {
0113       HostPtr host = m_item.staticCast<Smb4KHost>();
0114 
0115       if (host)
0116       {
0117         host->setLogin(user);
0118         host->setPassword(pass);
0119       }
0120 
0121       break;
0122     }
0123     case Share:
0124     {
0125       SharePtr share = m_item.staticCast<Smb4KShare>();
0126 
0127       if (share)
0128       {
0129         share->setLogin(user);
0130         share->setPassword(pass);
0131       }
0132 
0133       break;
0134     }
0135     default:
0136     {
0137       break;
0138     }
0139   }
0140 }
0141