File indexing completed on 2024-04-28 04:55:51

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #include "searchaction.h"
0010 
0011 #include <QAction>
0012 
0013 #include <KActionCollection>
0014 #include <KMessageBox>
0015 #include <KLocalizedString>
0016 #include <KPluginFactory>
0017 
0018 #include "choqokuiglobal.h"
0019 #include "microblogwidget.h"
0020 
0021 #include "twitterapiaccount.h"
0022 #include "twitterapimicroblog.h"
0023 
0024 K_PLUGIN_CLASS_WITH_JSON(SearchAction, "choqok_searchaction.json")
0025 
0026 SearchAction::SearchAction(QObject *parent, const QList< QVariant > &)
0027     : Plugin(QLatin1String("choqok_searchaction"), parent)
0028 {
0029     QAction *action = new QAction(QIcon::fromTheme(QLatin1String("edit-find")), i18n("Search..."), this);
0030     action->setShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_F));
0031     actionCollection()->addAction(QLatin1String("search"), action);
0032     connect(action, &QAction::triggered, this, &SearchAction::slotSearch);
0033     setXMLFile(QLatin1String("searchactionui.rc"));
0034 }
0035 
0036 SearchAction::~SearchAction()
0037 {
0038 
0039 }
0040 
0041 void SearchAction::slotSearch()
0042 {
0043     TwitterApiAccount *curAccount = qobject_cast<TwitterApiAccount *>(Choqok::UI::Global::mainWindow()->currentMicroBlog()->currentAccount());
0044     if (curAccount) {
0045         TwitterApiMicroBlog *mBlog = qobject_cast<TwitterApiMicroBlog *>(curAccount->microblog());
0046         mBlog->showSearchDialog(curAccount);
0047     } else {
0048       KMessageBox::error(Choqok::UI::Global::mainWindow(),
0049                          i18n("The Search action plugin does not support the "
0050                               "current microblog."));
0051     }
0052 }
0053 
0054 #include "moc_searchaction.cpp"
0055 #include "searchaction.moc"