summaryrefslogtreecommitdiffabout
path: root/korganizer/searchdialog.cpp
authorzautrix <zautrix>2005-06-25 02:44:17 (UTC)
committer zautrix <zautrix>2005-06-25 02:44:17 (UTC)
commitdcc7c9ed932ec2ef521aa04b929d0319f65c8bdc (patch) (side-by-side diff)
treef61360b8f883a6e5fe007c5a24cd35d7cc29ffc0 /korganizer/searchdialog.cpp
parent1d0b53abc70e66708d93b7081a21a7689b1a1303 (diff)
downloadkdepimpi-dcc7c9ed932ec2ef521aa04b929d0319f65c8bdc.zip
kdepimpi-dcc7c9ed932ec2ef521aa04b929d0319f65c8bdc.tar.gz
kdepimpi-dcc7c9ed932ec2ef521aa04b929d0319f65c8bdc.tar.bz2
serach fix
Diffstat (limited to 'korganizer/searchdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/searchdialog.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/korganizer/searchdialog.cpp b/korganizer/searchdialog.cpp
index 2390520..0e9f64c 100644
--- a/korganizer/searchdialog.cpp
+++ b/korganizer/searchdialog.cpp
@@ -80,439 +80,437 @@ SearchDialog::SearchDialog(Calendar *calendar,CalendarView *parent)
mSubItems->setFont( fo );
mRefineItems->setFont( fo );
connect( mAddItems , SIGNAL( toggled ( bool ) ),this,SLOT(slot_add( bool )));
connect( mSubItems , SIGNAL( toggled ( bool ) ),this,SLOT(slot_sub( bool )));
connect( mRefineItems , SIGNAL( toggled ( bool ) ),this,SLOT(slot_refine( bool )));
QPushButton *togButton = new QPushButton( "", topFrame );
subLayout->addWidget(togButton);
connect(togButton,SIGNAL(clicked()),SLOT(toggleCheckboxes()));
togButton->setPixmap(SmallIcon("1updownarrow"));
togButton->setMinimumWidth( togButton->sizeHint().height() );
searchEdit->setText("*"); // Find all events by default
searchEdit->setFocus();
connect(searchEdit, SIGNAL(textChanged ( const QString & )),this,SLOT(searchTextChanged( const QString & )));
connect(searchEdit, SIGNAL( returnPressed () ),this,SLOT(doSearch()));
// Subjects to search
// QGroupBox *subjectGroup = new QGroupBox(1,Vertical,i18n("Search In"),
// topFrame);
incidenceGroup = new QHBox( topFrame );
layout->addWidget(incidenceGroup);
mSearchEvent = new QCheckBox(i18n("Events"),incidenceGroup);
//mSearchEvent->setChecked(true);
mSearchTodo = new QCheckBox(i18n("Todos"),incidenceGroup);
mSearchJournal = new QCheckBox(i18n("Journals"),incidenceGroup);
subjectGroup = new QHBox( topFrame );
layout->addWidget(subjectGroup);
mSummaryCheck = new QCheckBox(i18n("Summary/Loc."),subjectGroup);
mSummaryCheck->setChecked(true);
mDescriptionCheck = new QCheckBox(i18n("Details"),subjectGroup);
mCategoryCheck = new QCheckBox(i18n("Categories"),subjectGroup);
attendeeGroup = new QHBox( topFrame );
layout->addWidget(attendeeGroup );
new QLabel( i18n("Attendee:"),attendeeGroup );
mSearchAName = new QCheckBox(i18n("Name"),attendeeGroup );
mSearchAEmail = new QCheckBox(i18n("Email"), attendeeGroup );
// Date range
// QGroupBox *rangeGroup = new QGroupBox(1,Horizontal,i18n("Date Range"),
// topFrame);
// layout->addWidget(rangeGroup);
QWidget *rangeWidget = new QWidget(topFrame);
QHBoxLayout *rangeLayout = new QHBoxLayout(rangeWidget,0,KDialog::spacingHint());
rangeLayout->addWidget(new QLabel(i18n("From:"),rangeWidget));
mStartDate = new KDateEdit(rangeWidget);
rangeLayout->addWidget(mStartDate);
rangeLayout->addWidget(new QLabel(i18n("To:"),rangeWidget));
mEndDate = new KDateEdit(rangeWidget);
mEndDate->setDate(QDate::currentDate().addDays(365));
rangeLayout->addWidget(mEndDate);
QToolButton *wt = QWhatsThis::whatsThisButton ( rangeWidget );
rangeLayout->addWidget( (QWidget*)wt );
layout->addWidget(rangeWidget);
// Results list view
listView = new KOListView(mCalendar,topFrame);
layout->addWidget(listView);
listView->showCompletedTodos();
//layout->setStretchFactor( listView, 333 );
//listView->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Expanding) );
//listView->setMaximumHeight( 50 );
listView->readSettings(KOGlobals::config(),"SearchListView Layout");
connect(searchEdit,SIGNAL(scrollDOWN()),SLOT(setFocusToList()));
setCaption( i18n("KO/Pi Find: "));
#ifdef DESKTOP_VERSION
OkButton = new QPushButton( i18n("Close"), this );
connect(OkButton,SIGNAL(clicked()),SLOT(hide()));
#endif
}
SearchDialog::~SearchDialog()
{
}
void SearchDialog::slot_add( bool b )
{
if ( b ) {
if ( mSubItems->isOn() ) mSubItems->toggle();
if ( mRefineItems->isOn() ) mRefineItems->toggle();
setCaption( i18n("Matching items will be added to list"));
} else
setCaption( i18n("List will be cleared before search"));
}
void SearchDialog::slot_sub( bool b)
{
if ( b ) {
if ( mRefineItems->isOn() ) mRefineItems->toggle();
if ( mAddItems->isOn() ) mAddItems->toggle();
setCaption( i18n("Matching items will be removed from list"));
} else
setCaption( i18n("List will be cleared before search"));
}
void SearchDialog::slot_refine( bool b)
{
if ( b ) {
if ( mSubItems->isOn() ) mSubItems->toggle();
if ( mAddItems->isOn() ) mAddItems->toggle();
setCaption( i18n("Search on displayed list only"));
} else
setCaption( i18n("List will be cleared before search"));
}
void SearchDialog::toggleCheckboxes()
{
if ( incidenceGroup->isVisible() ) {
incidenceGroup->hide() ;
subjectGroup->hide() ;
attendeeGroup->hide() ;
} else {
incidenceGroup->show() ;
subjectGroup->show() ;
attendeeGroup->show() ;
}
}
void SearchDialog::raiseAndSelect()
{
static int currentState = 0;
if ( !mSearchJournal->isChecked() && !mSearchTodo->isChecked() && !mSearchEvent->isChecked() )
currentState = 0;
int newState = 0;
if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
newState = VIEW_J_VIEW;
}
else if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
newState = VIEW_T_VIEW;
}
else {
newState = VIEW_A_VIEW;
}
if ( newState != currentState ) {
if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
if ( ! mSearchJournal->isChecked() ) {
mSearchJournal->setChecked( true );
mSearchTodo->setChecked( false );
mSearchEvent->setChecked( false );
}
}
else if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
if ( ! mSearchTodo->isChecked() ) {
mSearchTodo->setChecked( true );
mSearchJournal->setChecked( false );
mSearchEvent->setChecked( false );
}
}
else {
if ( ! mSearchEvent->isChecked() ) {
mSearchEvent->setChecked( true );
mSearchJournal->setChecked( false );
mSearchTodo->setChecked( false );
}
}
}
currentState = newState;
raise();
}
void SearchDialog::setFocusToList()
{
listView->resetFocus();
}
void SearchDialog::accept()
{
doSearch();
}
void SearchDialog::updateList()
{
//listView->updateList();
if ( isVisible() ) {
updateView();
//qDebug("SearchDialog::updated ");
}
else {
listView->clear();
//qDebug("SearchDialog::cleared ");
}
}
void SearchDialog::searchTextChanged( const QString &_text )
{
#if 0
enableButton( KDialogBase::User1, !_text.isEmpty() );
#endif
}
void SearchDialog::doSearch()
{
QRegExp re;
-
re.setWildcard(true); // most people understand these better.
re.setCaseSensitive(false);
QString st = searchEdit->text();
if ( st.right(1) != "*")
st += "*";
re.setPattern(st);
if (!mSearchEvent->isChecked() && !mSearchTodo->isChecked() && !mSearchJournal->isChecked() ) {
KMessageBox::sorry(this,
i18n("Please select at least one\nof the types to search for:\n\nEvents\nTodos\nJournals"));
return;
}
if (!re.isValid() ) {
KMessageBox::sorry(this,
i18n("Invalid search expression,\ncannot perform "
"the search.\nPlease enter a search expression\n"
"using the wildcard characters\n '*' and '?'"
"where needed."));
return;
}
search(re);
listView->setStartDate( mStartDate->date() );
listView->showEvents(mMatchedEvents);
listView->addTodos(mMatchedTodos);
listView->addJournals(mMatchedJournals);
if (mMatchedEvents.count() + mMatchedJournals.count() + mMatchedTodos.count() == 0) {
setCaption(i18n("No items found. Use '*' and '?' where needed."));
} else {
QString mess;
mess = mess.sprintf( i18n("%d item(s) found."), mMatchedEvents.count()+ mMatchedJournals.count() + mMatchedTodos.count() );
setCaption( i18n("KO/Pi Find: ") + mess);
}
searchEdit->setFocus();
}
void SearchDialog::updateConfig()
{
listView->updateConfig();
}
void SearchDialog::updateView()
{
//qDebug("SearchDialog::updateView() %d ", isVisible());
QRegExp re;
re.setWildcard(true); // most people understand these better.
re.setCaseSensitive(false);
QString st = searchEdit->text();
if ( st.right(1) != "*")
st += "*";
re.setPattern(st);
+ mMatchedEvents.clear();
+ mMatchedTodos.clear();
+ mMatchedJournals.clear();
if (re.isValid()) {
search(re);
- } else {
- mMatchedEvents.clear();
- mMatchedTodos.clear();
- mMatchedJournals.clear();
}
listView->setStartDate( mStartDate->date() );
listView->showEvents(mMatchedEvents);
listView->addTodos(mMatchedTodos);
listView->addJournals(mMatchedJournals);
}
void SearchDialog::search(const QRegExp &re)
{
QPtrList<Event> events;
if ( !mAddItems->isChecked() && !mSubItems->isChecked() ) {
if ( mRefineItems->isChecked() ) events = mMatchedEvents;
mMatchedEvents.clear();
}
if ( mSearchEvent->isChecked() ) {
if ( !mRefineItems->isChecked() )
events = mCalendar->events( mStartDate->date(),
mEndDate->date(),
false /*mInclusiveCheck->isChecked()*/ );
Event *ev;
for(ev=events.first();ev;ev=events.next()) {
if (mSummaryCheck->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(ev->summary()) != -1)
#else
if (re.match(ev->summary()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedEvents.remove(ev);
else {
if ( !mMatchedEvents.contains( ev ) )
mMatchedEvents.append(ev);
}
continue;
}
#if QT_VERSION >= 0x030000
if (re.search(ev->location()) != -1)
#else
if (re.match(ev->location()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedEvents.remove(ev);
else{
if ( !mMatchedEvents.contains( ev ) )
mMatchedEvents.append(ev);
}
continue;
}
}
if (mDescriptionCheck->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(ev->description()) != -1)
#else
if (re.match(ev->description()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedEvents.remove(ev);
else{
if ( !mMatchedEvents.contains( ev ) )
mMatchedEvents.append(ev);
}
continue;
}
}
if (mCategoryCheck->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(ev->categoriesStr()) != -1)
#else
if (re.match(ev->categoriesStr()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedEvents.remove(ev);
else{
if ( !mMatchedEvents.contains( ev ) )
mMatchedEvents.append(ev);
}
continue;
}
}
if ( mSearchAName->isChecked() || mSearchAEmail->isChecked() ) {
QPtrList<Attendee> tmpAList = ev->attendees();
Attendee *a;
for (a = tmpAList.first(); a; a = tmpAList.next()) {
if (mSearchAName->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(a->name()) != -1)
#else
if (re.match(a->name()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedEvents.remove(ev);
else{
if ( !mMatchedEvents.contains( ev ) )
mMatchedEvents.append(ev);
}
break;
}
}
if (mSearchAEmail->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(a->email()) != -1)
#else
if (re.match(a->email()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedEvents.remove(ev);
else{
if ( !mMatchedEvents.contains( ev ) )
mMatchedEvents.append(ev);
}
break;
}
}
}
}
}
}
QPtrList<Todo> todos;
if ( !mAddItems->isChecked() && !mSubItems->isChecked() ) {
if ( mRefineItems->isChecked() ) todos = mMatchedTodos ;
mMatchedTodos.clear();
}
if ( mSearchTodo->isChecked() ) {
if ( !mRefineItems->isChecked() ) todos = mCalendar->todos( );
Todo *tod;
for(tod=todos.first();tod;tod=todos.next()) {
if (mSummaryCheck->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(tod->summary()) != -1)
#else
if (re.match(tod->summary()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedTodos.remove(tod);
else if (!mMatchedTodos.contains( tod ))
mMatchedTodos.append(tod);
continue;
}
}
if (mDescriptionCheck->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(tod->description()) != -1)
#else
if (re.match(tod->description()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedTodos.remove(tod);
else if (!mMatchedTodos.contains( tod ))
mMatchedTodos.append(tod);
continue;
}
}
if (mCategoryCheck->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(tod->categoriesStr()) != -1)
#else
if (re.match(tod->categoriesStr()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedTodos.remove(tod);
else if (!mMatchedTodos.contains( tod ))
mMatchedTodos.append(tod);
continue;
}
}
if ( mSearchAName->isChecked() || mSearchAEmail->isChecked() ) {
QPtrList<Attendee> tmpAList = tod->attendees();
Attendee *a;
for (a = tmpAList.first(); a; a = tmpAList.next()) {
if (mSearchAName->isChecked()) {
#if QT_VERSION >= 0x030000
if (re.search(a->name()) != -1)
#else
if (re.match(a->name()) != -1)
#endif
{
if ( mSubItems->isChecked() )
mMatchedTodos.remove(tod);