summaryrefslogtreecommitdiffstats
path: root/smb4k/iconview/smb4ksharesiconviewitem.cpp
blob: 7a91f3d02e79174a5928c09d29bfb660f62976ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/***************************************************************************
    smb4ksharesiconviewitem  -  The items for Smb4K's shares icon view.
                             -------------------
    begin                : Di Dez 5 2006
    copyright            : (C) 2006 by Alexander Reinholdt
    email                : dustpuppy@users.berlios.de
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful, but   *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,   *
 *   MA  02110-1301 USA                                                    *
 ***************************************************************************/

// TQt includes
#include <tqpixmap.h>

// KDE includes
#include <kiconeffect.h>
#include <kdebug.h>

// application specific includes
#include "smb4ksharesiconviewitem.h"
#include "smb4ksharesiconview.h"

Smb4KSharesIconViewItem::Smb4KSharesIconViewItem( Smb4KShare *share, bool mountpoint,
                                                  Smb4KSharesIconView *parent )
: TDEIconViewItem( parent, TQString() ), m_share( *share ), m_mountpoint( mountpoint ),
  m_initial_setup( false )
{
  setDropEnabled( true );
  setDragEnabled( true );

  m_loader = new TDEIconLoader();

  setupItem( m_share, m_mountpoint );
}


Smb4KSharesIconViewItem::~Smb4KSharesIconViewItem()
{
  // Do not touch the Smb4KShare object!
  delete m_loader;
}


void Smb4KSharesIconViewItem::paintItem( TQPainter *p, const TQColorGroup &cg )
{
  // Set the color of the item text:
  TQColorGroup colorgrp( cg );

  if ( m_share.isForeign() )
  {
    colorgrp.setColor( TQColorGroup::Text, TQt::gray );
  }

  TQIconViewItem::paintItem( p, colorgrp );
}


bool Smb4KSharesIconViewItem::acceptDrop( const TQMimeSource *source ) const
{
  if ( source->provides( "text/plain" ) )
  {
    return true;
  }

  return false;
}


void Smb4KSharesIconViewItem::setupItem( const Smb4KShare &share, bool mountpoint )
{
  // Only do something here if either the item hasn't been set up
  // yet, or share and mountpoint changed, respectively.
  if ( !m_initial_setup || !m_share.equals( share ) || m_mountpoint != mountpoint )
  {
    if ( !m_initial_setup || m_share.isBroken() != share.isBroken() )
    {
      int icon_state = m_share.isForeign() ? TDEIcon::DisabledState : TDEIcon::DefaultState;

      if ( m_share.isBroken() )
      {
        TQImage over = m_loader->loadIcon( "button_cancel", TDEIcon::Desktop,
                                          0, icon_state, 0L, false ).convertToImage();
        TQImage src = m_loader->loadIcon( "drive-harddisk-mounted", TDEIcon::Desktop,
                                         0, icon_state, 0L, false ).convertToImage();

        TDEIconEffect e;
        e.semiTransparent( over );
        e.overlay( src, over );

        m_pixmap = TQPixmap( src );
      }
      else
      {
        m_pixmap = m_loader->loadIcon( "drive-harddisk-mounted", TDEIcon::Desktop,
                                       0, icon_state, 0L, false );
      }

      setPixmap( m_pixmap );
    }
    else
    {
      // Do nothing
    }

    if ( !m_initial_setup || m_mountpoint != mountpoint )
    {
      setText( (m_mountpoint ? m_share.path() : m_share.name()) );
    }
    else
    {
      // Do nothing
    }

    m_initial_setup = true;
    m_share = share;
    m_mountpoint = mountpoint;
  }
  else
  {
    // Do nothing
  }
}


bool Smb4KSharesIconViewItem::sameShareObject( Smb4KShare *share )
{
  return m_share.equals( *share );
}


void Smb4KSharesIconViewItem::replaceShareObject( Smb4KShare *share )
{
  setupItem( *share, m_mountpoint );
}