• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • search
searchcontroller.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2006-2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "searchcontroller.h"
24 
25 // controller
26 #include "ksearchdialog.h"
27 #include "searchtool.h"
28 // KDE
29 #include <KXMLGUIClient>
30 #include <KLocale>
31 #include <KAction>
32 #include <KActionCollection>
33 #include <KStandardAction>
34 #include <KMessageBox>
35 
36 
37 namespace Kasten2
38 {
39 
40 // TODO: for docked widgets signal widgets if embedded or floating, if horizontal/vertical
41 SearchController::SearchController( KXMLGUIClient* guiClient, QWidget* parentWidget )
42  : mParentWidget( parentWidget ),
43  mSearchDialog( 0 )
44 {
45  KActionCollection* actionCollection = guiClient->actionCollection();
46 
47  mFindAction = KStandardAction::find( this, SLOT(find()), actionCollection );
48  mFindNextAction = KStandardAction::findNext( this, SLOT(findNext()), actionCollection );
49  mFindPrevAction = KStandardAction::findPrev( this, SLOT(findPrevious()), actionCollection );
50 
51  mTool = new SearchTool();
52  mTool->setUserQueryAgent( this );
53 
54  connect( mTool, SIGNAL(isApplyableChanged(bool)),
55  mFindAction, SLOT(setEnabled(bool)) );
56  connect( mTool, SIGNAL(isApplyableChanged(bool)),
57  mFindNextAction, SLOT(setEnabled(bool)) );
58  connect( mTool, SIGNAL(isApplyableChanged(bool)),
59  mFindPrevAction, SLOT(setEnabled(bool)) );
60 
61  connect( mTool, SIGNAL(dataNotFound()), SLOT(onDataNotFound()) );
62 
63  mFindAction->setEnabled( false );
64  mFindNextAction->setEnabled( false );
65  mFindPrevAction->setEnabled( false );
66 }
67 
68 void SearchController::setTargetModel( AbstractModel* model )
69 {
70  mTool->setTargetModel( model );
71 }
72 
73 void SearchController::find()
74 {
75  showDialog( FindForward );
76 }
77 
78 void SearchController::findNext()
79 {
80  if( mTool->searchData().isEmpty() )
81  showDialog( FindForward );
82  else
83  mTool->search( FindForward, true, false );
84 ;
85 }
86 
87 void SearchController::findPrevious()
88 {
89  if( mTool->searchData().isEmpty() )
90  showDialog( FindBackward );
91  else
92  mTool->search( FindBackward, true, false );
93 }
94 
95 void SearchController::showDialog( KFindDirection direction )
96 {
97  // ensure dialog
98  if( !mSearchDialog )
99  mSearchDialog = new KSearchDialog( mTool, mParentWidget );
100 
101  mSearchDialog->setDirection( direction );
102 
103  mSearchDialog->show();
104 }
105 
106 void SearchController::onDataNotFound()
107 {
108  const QString messageBoxTitle = i18nc( "@title:window", "Find" );
109  KMessageBox::sorry( mParentWidget, i18nc("@info","Search key not found in byte array."), messageBoxTitle );
110 }
111 
112 bool SearchController::queryContinue( KFindDirection direction ) const
113 {
114  const QString messageBoxTitle = i18nc( "@title:window", "Find" );
115  const QString question = ( direction == FindForward ) ?
116  i18nc( "@info", "End of byte array reached.<nl/>Continue from the beginning?" ) :
117  i18nc( "@info", "Beginning of byte array reached.<nl/>Continue from the end?" );
118 
119  const int answer = KMessageBox::questionYesNo( mParentWidget, question, messageBoxTitle,
120  KStandardGuiItem::cont(), KStandardGuiItem::cancel() );
121 
122  const bool result = ( answer != KMessageBox::No );
123 
124  return result;
125 }
126 
127 SearchController::~SearchController()
128 {
129  delete mSearchDialog;
130  delete mTool;
131 }
132 
133 }
searchcontroller.h
searchtool.h
Kasten2::SearchController::~SearchController
virtual ~SearchController()
Definition: searchcontroller.cpp:127
Kasten2::SearchTool::searchData
QByteArray searchData() const
Definition: searchtool.h:106
QWidget
Kasten2::SearchTool::search
void search(KFindDirection direction, bool fromCursor, bool inSelection)
Definition: searchtool.cpp:119
Kasten2::FindForward
Definition: kfinddirection.h:30
Kasten2::SearchController::queryContinue
virtual bool queryContinue(KFindDirection direction) const
Definition: searchcontroller.cpp:112
Kasten2::SearchTool
Definition: searchtool.h:47
Kasten2::SearchController::SearchController
SearchController(KXMLGUIClient *guiClient, QWidget *parentWidget)
Definition: searchcontroller.cpp:41
Kasten2::SearchTool::setUserQueryAgent
void setUserQueryAgent(If::SearchUserQueryable *userQueryAgent)
Definition: searchtool.cpp:92
Kasten2::SearchTool::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: searchtool.cpp:66
Kasten2::KAbstractFindDialog::setDirection
void setDirection(KFindDirection Direction)
Definition: kabstractfinddialog.cpp:148
Kasten2::SearchController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: searchcontroller.cpp:68
ksearchdialog.h
Kasten2::KFindDirection
KFindDirection
Definition: kfinddirection.h:29
Kasten2::No
Definition: kastencore.h:63
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::FindBackward
Definition: kfinddirection.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal