~ubuntu-branches/ubuntu/vivid/smb4k/vivid

« back to all changes in this revision

Viewing changes to core/smb4kwalletmanager_p.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-06-15 16:27:38 UTC
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20140615162738-t1426an8s5beix1b
Tags: upstream-1.1.2
ImportĀ upstreamĀ versionĀ 1.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    smb4kwalletmanager_p  -  Private helper classes for the wallet manager
 
3
                             of Smb4K.
 
4
                             -------------------
 
5
    begin                : Mo Dez 31 2012
 
6
    copyright            : (C) 2012 by Alexander Reinholdt
 
7
    email                : alexander.reinholdt@kdemail.net
 
8
 ***************************************************************************/
 
9
 
 
10
/***************************************************************************
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 *   This program is distributed in the hope that it will be useful, but   *
 
17
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
18
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 
19
 *   General Public License for more details.                              *
 
20
 *                                                                         *
 
21
 *   You should have received a copy of the GNU General Public License     *
 
22
 *   along with this program; if not, write to the                         *
 
23
 *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
 
24
 *   MA 02110-1335, USA                                                    *
 
25
 ***************************************************************************/
 
26
 
 
27
// application specific includes
 
28
#include "smb4kwalletmanager_p.h"
 
29
#include "smb4khost.h"
 
30
#include "smb4kshare.h"
 
31
#include "smb4khomesshareshandler.h"
 
32
 
 
33
// Qt includes
 
34
#include <QtCore/QDebug>
 
35
 
 
36
// KDE includes
 
37
#include <klocale.h>
 
38
 
 
39
 
 
40
Smb4KPasswordDialog::Smb4KPasswordDialog( Smb4KBasicNetworkItem* networkItem, const QMap<QString,QString> &knownLogins, QWidget* parent )
 
41
: KPasswordDialog( parent, KPasswordDialog::ShowUsernameLine )
 
42
{
 
43
  m_item = networkItem;
 
44
  
 
45
  switch ( m_item->type() )
 
46
  {
 
47
    case Smb4KBasicNetworkItem::Host:
 
48
    {
 
49
      Smb4KHost *host = static_cast<Smb4KHost *>( m_item );
 
50
 
 
51
      if ( host )
 
52
      {
 
53
        setUsername( host->login() );
 
54
        setPassword( host->password() );
 
55
        setPrompt( i18n( "<qt>Please enter a username and a password for the host <b>%1</b>.</qt>", host->hostName() ) );
 
56
      }
 
57
      else
 
58
      {
 
59
        // Do nothing
 
60
      }
 
61
      break;
 
62
    }
 
63
    case Smb4KBasicNetworkItem::Share:
 
64
    {
 
65
      Smb4KShare *share = static_cast<Smb4KShare *>( m_item );
 
66
 
 
67
      if ( share )
 
68
      {
 
69
        // Enter authentication information into the dialog
 
70
        if ( !knownLogins.isEmpty() )
 
71
        {
 
72
          setKnownLogins( knownLogins );
 
73
        }
 
74
        else
 
75
        {
 
76
          setUsername( share->login() );
 
77
          setPassword( share->password() );
 
78
        }
 
79
 
 
80
        if ( !share->isHomesShare() )
 
81
        {
 
82
          setPrompt( i18n( "<qt>Please enter a username and a password for the share <b>%1</b>.</qt>", share->unc() ) );
 
83
        }
 
84
        else
 
85
        {
 
86
          setPrompt( i18n( "<qt>Please enter a username and a password for the share <b>%1</b>.</qt>", share->homeUNC() ) );
 
87
        }
 
88
      }
 
89
      else
 
90
      {
 
91
        // Do nothing
 
92
      }
 
93
      break;
 
94
    }
 
95
    default:
 
96
    {
 
97
      break;
 
98
    }
 
99
  }
 
100
 
 
101
  connect( this, SIGNAL(gotUsernameAndPassword(QString,QString,bool)), SLOT(slotGotUsernameAndPassword(QString,QString,bool)) );
 
102
}
 
103
 
 
104
 
 
105
Smb4KPasswordDialog::~Smb4KPasswordDialog()
 
106
{
 
107
}
 
108
 
 
109
 
 
110
void Smb4KPasswordDialog::slotGotUsernameAndPassword( const QString &user, const QString &pass, bool /*keep*/ )
 
111
{
 
112
  switch ( m_item->type() )
 
113
  {
 
114
    case Smb4KBasicNetworkItem::Host:
 
115
    {
 
116
      Smb4KHost *host = static_cast<Smb4KHost *>( m_item );
 
117
 
 
118
      if ( host )
 
119
      {
 
120
        host->setLogin( user );
 
121
        host->setPassword( pass );
 
122
      }
 
123
      else
 
124
      {
 
125
        // Do nothing
 
126
      }
 
127
      break;
 
128
    }
 
129
    case Smb4KBasicNetworkItem::Share:
 
130
    {
 
131
      Smb4KShare *share = static_cast<Smb4KShare *>( m_item );
 
132
 
 
133
      if ( share )
 
134
      {
 
135
        share->setLogin( user );
 
136
        share->setPassword( pass );
 
137
      }
 
138
      else
 
139
      {
 
140
        // Do nothing
 
141
      }
 
142
      break;
 
143
    }
 
144
    default:
 
145
    {
 
146
      break;
 
147
    }
 
148
  }
 
149
}
 
150
 
 
151
 
 
152
#include "smb4kwalletmanager_p.moc"