• 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
  • replace
replacecontroller.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 "replacecontroller.h"
24 
25 // controller
26 #include "kreplacedialog.h"
27 #include "kreplaceprompt.h"
28 #include "replacetool.h"
29 // KDE
30 #include <KXmlGuiWindow>
31 #include <KLocale>
32 #include <KAction>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KMessageBox>
36 // Qt
37 #include <QtGui/QApplication>
38 
39 
40 namespace Kasten2
41 {
42 
43 // TODO: for docked widgets signal widgets if embedded or floating, if horizontal/vertical
44 ReplaceController::ReplaceController( KXMLGUIClient* guiClient, QWidget* parentWidget )
45  : mParentWidget( parentWidget ),
46  mReplaceDialog( 0 ),
47  mReplacePrompt( 0 )
48 {
49  KActionCollection* ActionCollection = guiClient->actionCollection();
50 
51  mReplaceAction = KStandardAction::replace( this, SLOT(replace()), ActionCollection );
52 
53  mTool = new ReplaceTool();
54  mTool->setUserQueryAgent( this );
55 
56  connect( mTool, SIGNAL(isApplyableChanged(bool)),
57  mReplaceAction, SLOT(setEnabled(bool)) );
58 
59  connect( mTool, SIGNAL(finished(bool,int)), SLOT(onFinished(bool,int)) );
60 
61  mReplaceAction->setEnabled( false );
62 }
63 
64 void ReplaceController::setTargetModel( AbstractModel* model )
65 {
66  mTool->setTargetModel( model );
67 }
68 
69 void ReplaceController::replace()
70 {
71  // ensure dialog
72  if( !mReplaceDialog )
73  mReplaceDialog = new KReplaceDialog( mTool, mParentWidget );
74 
75  mReplaceDialog->show();
76 }
77 
78 
79 void ReplaceController::onFinished( bool previousFound, int noOfReplacements )
80 {
81  if( mReplacePrompt )
82  mReplacePrompt->hide();
83 
84  const QString messageBoxTitle = i18nc( "@title:window", "Replace" );
85  const QString replacementReport = (noOfReplacements==0) ?
86  i18nc( "@info", "No replacements made.") :
87  i18ncp( "@info", "1 replacement made.", "%1 replacements made.", noOfReplacements );
88 
89  if( ! previousFound )
90  KMessageBox::sorry( mParentWidget, i18nc("@info","Replace pattern not found in byte array."), messageBoxTitle );
91  else
92  KMessageBox::information( mParentWidget, replacementReport, messageBoxTitle );
93 }
94 
95 bool ReplaceController::queryContinue( KFindDirection direction, int noOfReplacements ) const
96 {
97  const QString messageBoxTitle = i18nc( "@title:window", "Replace" );
98  const QString replacementReport = (noOfReplacements==0) ?
99  i18nc( "@info", "No replacements made.") :
100  i18ncp( "@info", "1 replacement made.", "%1 replacements made.", noOfReplacements );
101  const QString question = ( direction == FindForward ) ?
102  i18nc( "@info", "End of byte array reached.<nl/>Continue from the beginning?" ) :
103  i18nc( "@info", "Beginning of byte array reached.<nl/>Continue from the end?" );
104 
105  const QString message = replacementReport + QLatin1String("<br /><br />") + question;
106  const int answer = KMessageBox::questionYesNo( mParentWidget, message, messageBoxTitle,
107  KStandardGuiItem::cont(), KStandardGuiItem::cancel() );
108 
109  const bool result = ( answer != KMessageBox::No );
110 
111  return result;
112 }
113 
114 ReplaceBehaviour ReplaceController::queryReplaceCurrent() const
115 {
116  if( !mReplacePrompt )
117  mReplacePrompt = new KReplacePrompt( mParentWidget );
118 
119  mReplacePrompt->show();
120  const ReplaceBehaviour answer = mReplacePrompt->query();
121 
122  if( answer == ReplaceAll || answer == CancelReplacing )
123  mReplacePrompt->hide();
124 
125  return answer;
126 }
127 
128 ReplaceController::~ReplaceController()
129 {
130  delete mReplaceDialog;
131  delete mReplacePrompt;
132  delete mTool;
133 }
134 
135 }
Kasten2::ReplaceTool::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: replacetool.cpp:68
replacecontroller.h
Kasten2::KReplaceDialog
Definition: kreplacedialog.h:36
Kasten2::ReplaceAll
Definition: replaceuserqueryable.h:35
Kasten2::ReplaceController::queryReplaceCurrent
virtual ReplaceBehaviour queryReplaceCurrent() const
Definition: replacecontroller.cpp:114
Kasten2::KReplacePrompt
Definition: kreplaceprompt.h:37
QWidget
Kasten2::FindForward
Definition: kfinddirection.h:30
kreplacedialog.h
Kasten2::ReplaceController::queryContinue
virtual bool queryContinue(KFindDirection direction, int noOfReplacements) const
Definition: replacecontroller.cpp:95
kreplaceprompt.h
Kasten2::ReplaceController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: replacecontroller.cpp:64
Kasten2::ReplaceController::ReplaceController
ReplaceController(KXMLGUIClient *guiClient, QWidget *parentWidget)
Definition: replacecontroller.cpp:44
Kasten2::ReplaceTool
Definition: replacetool.h:48
Kasten2::ReplaceController::~ReplaceController
virtual ~ReplaceController()
Definition: replacecontroller.cpp:128
replacetool.h
Kasten2::KFindDirection
KFindDirection
Definition: kfinddirection.h:29
Kasten2::ReplaceTool::setUserQueryAgent
void setUserQueryAgent(If::ReplaceUserQueryable *userQueryAgent)
Definition: replacetool.cpp:93
Kasten2::No
Definition: kastencore.h:63
Kasten2::KReplacePrompt::query
ReplaceBehaviour query()
Definition: kreplaceprompt.cpp:52
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::ReplaceBehaviour
ReplaceBehaviour
Definition: replaceuserqueryable.h:35
Kasten2::CancelReplacing
Definition: replaceuserqueryable.h:35
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