summaryrefslogtreecommitdiffstats
path: root/smb4k/searchdlg/smb4ksearchdialog.cpp
blob: c9b4612eb7c67bc29b241ea056a0e03bc400c1b3 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/***************************************************************************
    smb4ksearchdialog  -  The search dialog widget of Smb4K.
                             -------------------
    begin                : Sa Jun 2 2007
    copyright            : (C) 2007 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 <tqlayout.h>
#include <tqstringlist.h>
#include <tqheader.h>

// KDE includes
#include <tdelocale.h>
#include <kdebug.h>
#include <kcombobox.h>

// application specific includes
#include "smb4ksearchdialog.h"
#include "smb4ksearchdialogitem.h"
#include "../core/smb4knetworkitems.h"

Smb4KSearchDialog::Smb4KSearchDialog( TQWidget *parent, const char *name )
: TQWidget( parent, name )
{
  TQGridLayout *layout = new TQGridLayout( this );
  layout->setSpacing( 5 );

  // Tool bar
  m_tool_bar = new TDEToolBar( this, "SearchDialogToolBar", true, true );

  m_tool_bar->insertCombo( TQStringList(), Combo, true, TQ_SIGNAL( returnPressed() ),
                           this, TQ_SLOT( slotReturnPressed() ), true,
                           i18n( "Enter the search string here." ), -1, Combo );
  m_tool_bar->setItemAutoSized( Combo, true );

  m_tool_bar->insertSeparator();

  m_tool_bar->insertButton( "edit-find", Search, false, i18n( "Search" ) );
  m_tool_bar->insertButton( "edit-delete", Clear, false, i18n( "Clear" ) );
  m_tool_bar->insertButton( "button_ok", Add, false, i18n( "Add" ) );

  // List view
  m_list_view = new TDEListView( this, "SearchDialogListView" );
  m_list_view->addColumn( i18n( "Search Results" ), -1 );
  m_list_view->header()->hide();
  m_list_view->setSelectionMode( TQListView::Single );

  layout->addWidget( m_tool_bar, 0, 0, 0 );
  layout->addWidget( m_list_view, 1, 0, 0 );

  m_search_string = TQString();

  // Connections:
  connect( m_tool_bar->getCombo( Combo ), TQ_SIGNAL( textChanged( const TQString & ) ),
           this,                          TQ_SLOT( slotTextChanged( const TQString & ) ) );

  connect( m_tool_bar,                    TQ_SIGNAL( pressed( int ) ),
           this,                          TQ_SLOT( slotButtonPressed( int ) ) );

  connect( m_list_view,                   TQ_SIGNAL( clicked( TQListViewItem * )  ),
           this,                          TQ_SLOT( slotItemClicked( TQListViewItem * ) ) );

  connect( m_list_view,                   TQ_SIGNAL( selectionChanged( TQListViewItem * )  ),
           this,                          TQ_SLOT( slotSelectionChanged( TQListViewItem * ) ) );
}


Smb4KSearchDialog::~Smb4KSearchDialog()
{
}


const TQString &Smb4KSearchDialog::searchString()
{
  m_search_string = m_tool_bar->getCombo( Combo )->currentText();

  return m_search_string;
}


/////////////////////////////////////////////////////////////////////////////
// SLOT IMPLEMENTATIONS
/////////////////////////////////////////////////////////////////////////////

void Smb4KSearchDialog::slotReturnPressed()
{
  slotButtonPressed( Search );
}


void Smb4KSearchDialog::slotTextChanged( const TQString &text )
{
  m_tool_bar->setItemEnabled( Search, !text.isEmpty() );
  m_tool_bar->setItemEnabled( Clear, !text.isEmpty() );
}


void Smb4KSearchDialog::slotButtonPressed( int button_id )
{
  switch( button_id )
  {
    case Search:
    {
      // We will not remove the text from the edit line of the combo
      // box like in earlier versions of Smb4K, but it will be selected
      // later on, so that the user can easily remove it, if he wants to.
      // We disable the combo box until the search process returns.
      m_tool_bar->setItemEnabled( Combo, false );

      break;
    }
    case Clear:
    {
      // Clear the combo box and the list view. The buttons
      // will be disabled by slotTextChanged().
      m_tool_bar->getCombo( Combo )->clear();
      m_list_view->clear();

      m_tool_bar->setItemEnabled( Search, false );
      m_tool_bar->setItemEnabled( Clear, false );
      m_tool_bar->setItemEnabled( Add, false );

      break;
    }
    default:
    {
      break;
    }
  }

  emit buttonPressed( button_id );
}


void Smb4KSearchDialog::slotItemClicked( TQListViewItem *item )
{
  if ( !item )
  {
    // If there is no item, it means that the user clicked onto
    // the viewport. In this case, disable the "Add" button and
    // clear the current selection.
    m_tool_bar->setItemEnabled( Add, false );

    m_list_view->clearSelection();
  }
  else
  {
    // This is done by slotSelectionChanged().
  }
}


void Smb4KSearchDialog::slotSelectionChanged( TQListViewItem *item )
{
  if ( item )
  {
    // If we have got an item, enable the "Add" button if the
    // item is regular. Otherwise disable the button.
    Smb4KSearchDialogItem *search_item = static_cast<Smb4KSearchDialogItem *>( item );

    if ( search_item->isRegular() )
    {
      m_tool_bar->setItemEnabled( Add, true );
    }
    else
    {
      m_tool_bar->setItemEnabled( Add, false );
    }
  }
  else
  {
    // If there is no item, it means that the user clicked onto
    // the viewport. In this case, disable the "Add" button and
    // clear the current selection.
    m_tool_bar->setItemEnabled( Add, false );

    m_list_view->clearSelection();
  }
}

#include "smb4ksearchdialog.moc"