void TweaksPlugin::patchLibraryMenu() { cout << "TweaksPlugin::patchMenu()" << endl << flush; LibraryMenuController *lmc = QApplication::activeWindow()->findChild<LibraryMenuController *>(); NickelTouchMenu *ntm = QApplication::activeWindow()->findChild<NickelTouchMenu *>(); if (lmc && ntm && lastPatchedLibraryMenu != (void *) ntm) { // Clear menu and add entries based on configuration if(pluginSettings->value("Library/customMenuEnabled", false).toBool()) { ntm->clear(); if(pluginSettings->value("Library/showBooks", true).toBool()) createLibraryMenuEntry(MENTRY_BOOKS, tr("Books")); if(pluginSettings->value("Library/showSortlist", true).toBool()) createLibraryMenuEntry(MENTRY_SHORTLIST, tr("Shortlist")); if(pluginSettings->value("Library/showSearch", true).toBool()) createLibraryMenuEntry(MENTRY_LIBRARYSEARCH, tr("Library Search")); } if(pluginSettings->value("Library/showShelves", true).toBool()) { createLibraryMenuEntry(MENTRY_CREATESHELF, tr("Create Shelf")); createLibraryMenuEntry(MENTRY_SHELVES, tr("Bookshelves")); } // store that we already patched this menu so the item doesn't get added twice lastPatchedLibraryMenu = (void *) ntm; cout << "TweaksPlugin::patchMenu(), success!" << endl << flush; } }
void TweaksPlugin::patchReadingLife() { LOG_TRACE(l); FooterLabelWidget *readingLife = qApp->activeWindow()->findChild<FooterLabelWidget *>("readingLife"); if(readingLife) { ReadingLifeMenuController* fbmc = readingLife->findChildren<ReadingLifeMenuController *>().last(); NickelTouchMenu *ntm = readingLife->findChildren<NickelTouchMenu *>().last(); if (fbmc && ntm) { // Clear menu and add entries based on configuration static QPoint origPos = ntm->pos(); static int elemHeight = ntm->sizeHint().height()/2; ntm->clear(); QList<MenuEntry>::iterator it; int activeEntries = 0; for(it = menuEntries.begin(); it != menuEntries.end(); it++) { if (it->enabled()) { MenuTextItem *mti = NULL; mti = fbmc->createMenuTextItem(ntm, it->name(), false, false); mti->setSelected(false); fbmc->addWidgetActionWithMapper(ntm, mti, &mapper, it->action(), true, true); ntm->addSeparator(); activeEntries++; } } pluginSettings->beginGroup("CustomCommands"); QStringList keys = pluginSettings->allKeys(); QList<QString>::iterator keyit; for(keyit = keys.begin(); keyit != keys.end(); keyit++) { LOG_DEBUG(l) << "custom command: " << keyit->toStdString(); QString action = pluginSettings->value(*keyit,QString()).toString(); LOG_DEBUG(l) << "action: " << action.toStdString(); MenuTextItem *mti = NULL; mti = fbmc->createMenuTextItem(ntm, *keyit, false, false); mti->setSelected(false); fbmc->addWidgetActionWithMapper(ntm, mti, &mapper, action, true, true); ntm->addSeparator(); activeEntries++; } pluginSettings->endGroup(); QPoint x = origPos; x.setY(origPos.y() + (2 - activeEntries) * elemHeight); x.setY(x.y() + (abs(2 - activeEntries) * 10)); //cout << qPrintable(QString("x %1 | y %2").arg(x.x()).arg(x.y())) << endl << flush; ntm->move(x); ntm->update(); ntm->layout(); } } }
void TweaksPlugin::patchMenu() { //LOG("patchMenu"); cout << "TweaksPlugin::patchMenu()" << endl << flush; hmc = QApplication::activeWindow()->findChild<HomeMenuController *>(); LibraryMenuController *lmc = QApplication::activeWindow()->findChild<LibraryMenuController *>(); NickelTouchMenu *ntm = QApplication::activeWindow()->findChild<NickelTouchMenu *>(); cout << "TweaksPlugin::patchMenu(), ntm: " << ntm << ", hmc: " << hmc << endl << flush; if (hmc && ntm && lastPatchedMenu != (void *) ntm) { // Clear menu and add entries based on configuration if(pluginSettings->value("Menu/customMenuEnabled", true).toBool()) { ntm->clear(); if(pluginSettings->value("Menu/showLibrary", true).toBool()) createHomeMenuEntry(MENTRY_LIBRARY, ":/images/menu/trilogy_library.png", tr("Library"), hmc, ntm); if(lmc && pluginSettings->value("Menu/showShortlist", false).toBool()) createHomeMenuEntry(MENTRY_SHORTLIST, ":/koboplugins/icons/menu/shortlist_01.png", tr("Shortlist"), hmc, ntm); if(lmc && pluginSettings->value("Menu/showShelves", false).toBool()) createHomeMenuEntry(MENTRY_SHELVES, ":/koboplugins/icons/menu/shelve_02.png", tr("Bookshelves"), hmc, ntm); if(lmc && pluginSettings->value("Menu/showSearch", true).toBool()) createHomeMenuEntry(MENTRY_LIBRARYSEARCH, ":/koboplugins/icons/menu/search_02.png", tr("Library Search"), hmc, ntm); if(pluginSettings->value("Menu/showDictionary", true).toBool()) createHomeMenuEntry(MENTRY_DICTIONARY, ":/koboplugins/icons/menu/dictionary_01.png", tr("Dictionary"), hmc, ntm); if(pluginSettings->value("Menu/showReadingLife", true).toBool()) createHomeMenuEntry(MENTRY_READINGLIFE, ":/images/menu/trilogy_readinglife.png", tr("Reading Life"), hmc, ntm); if(pluginSettings->value("Menu/showStore", true).toBool()) createHomeMenuEntry(MENTRY_STORE, ":/images/menu/trilogy_store.png", tr("Store"), hmc, ntm); if(pluginSettings->value("Menu/showSync", true).toBool()) createHomeMenuEntry(MENTRY_SYNC, ":/images/menu/trilogy_sync.png", tr("Sync"), hmc, ntm); if(pluginSettings->value("Menu/showHelp", true).toBool()) createHomeMenuEntry(MENTRY_HELP, ":/images/menu/trilogy_help.png", tr("Help"), hmc, ntm); createHomeMenuEntry(MENTRY_SETTINGS, ":/images/menu/trilogy_settings.png", tr("Settings"), hmc, ntm); } else { if(lmc && pluginSettings->value("Menu/showShortlist", false).toBool()) createHomeMenuEntry(MENTRY_SHORTLIST, ":/koboplugins/icons/menu/shortlist_01.png", tr("Shortlist"), hmc, ntm); } if(pluginSettings->value("Menu/showTweaksEntry", true).toBool()) createHomeMenuEntry(MENTRY_TWEAKS, ":/koboplugins/icons/menu/tweak_01.png", tr("Tweaks"), hmc, ntm); if(pluginSettings->value("Menu/showBrowser", false).toBool()) createHomeMenuEntry(MENTRY_BROWSER, ":/koboplugins/icons/menu/browser_02.png", tr("Browser"), hmc, ntm); if(pluginSettings->value("Menu/showAirplaneMode", false).toBool()) createHomeMenuEntry(MENTRY_AIRPLANEMODE, ":/images/statusbar/wifi_airplane.png", tr("Airplane Mode"), hmc, ntm); if(pluginSettings->value("Menu/showWifiOnOff", false).toBool()) createHomeMenuEntry(MENTRY_WIFIONOFF, ":/images/statusbar/wifi_4.png", tr("Toggle WiFi"), hmc, ntm); if(pluginSettings->value("Menu/showPowerOff", false).toBool()) createHomeMenuEntry(MENTRY_POWEROFF, ":/koboplugins/icons/menu/power_01.png", tr("Power Off"), hmc, ntm); if(pluginSettings->value("Menu/showSleep", false).toBool()) createHomeMenuEntry(MENTRY_SLEEP, ":/koboplugins/icons/menu/sleep_01.png", tr("Sleep"), hmc, ntm); // store that we already patched this menu so the item doesn't get added twice lastPatchedMenu = (void *) ntm; cout << "TweaksPlugin::patchMenu(), success!" << endl << flush; } }