Status RegistryFactory::addBroadcast(const RouteUUID& uuid, const RegistryBroadcast& broadcast) { WriteLock lock(mutex_); if (extensions_.count(uuid) > 0) { return Status(1, "Duplicate extension UUID: " + std::to_string(uuid)); } // Make sure the extension does not broadcast conflicting registry items. if (!allowDuplicates()) { for (const auto& registry : broadcast) { for (const auto& item : registry.second) { if (exists(registry.first, item.first)) { VLOG(1) << "Extension " << uuid << " has duplicate plugin name: " << item.first << " in registry: " << registry.first; return Status(1, "Duplicate registry item: " + item.first); } } } } // Once duplication is satisfied call each registry's addExternal. Status status; for (const auto& registry : broadcast) { if (!exists(registry.first)) { VLOG(1) << "Extension " << uuid << "contains unknown registry: " << registry.first; return Status(1, "Unknown registry: " + registry.first); } status = this->registry(registry.first)->addExternal(uuid, registry.second); if (!status.ok()) { // If any registry fails to add the set of external routes, stop. break; } for (const auto& plugin : registry.second) { VLOG(1) << "Extension " << uuid << " registered " << registry.first << " plugin " << plugin.first; } } // If any registry failed, remove each (assume a broadcast is atomic). if (!status.ok()) { for (const auto& registry : broadcast) { this->registry(registry.first)->removeExternal(uuid); } } extensions_.insert(uuid); return status; }
bool OperaBookmarksImporter::import(const QString &path) { QFile file(getSuggestedPath(path)); if (!file.open(QIODevice::ReadOnly)) { return false; } QTextStream stream(&file); stream.setCodec("UTF-8"); QString line(stream.readLine()); if (line != QLatin1String("Opera Hotlist version 2.0")) { return false; } if (m_optionsWidget) { if (m_optionsWidget->hasToRemoveExisting()) { removeAllBookmarks(); if (m_optionsWidget->isImportingIntoSubfolder()) { setImportFolder(BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), m_optionsWidget->getSubfolderName(), BookmarksManager::getModel()->getRootItem())); } else { setImportFolder(BookmarksManager::getModel()->getRootItem()); } } else { setAllowDuplicates(m_optionsWidget->allowDuplicates()); setImportFolder(m_optionsWidget->getTargetFolder()); } } BookmarksItem *bookmark(NULL); OperaBookmarkEntry type(NoEntry); bool isHeader(true); while (!stream.atEnd()) { line = stream.readLine(); if (isHeader && (line.isEmpty() || line.at(0) != QLatin1Char('#'))) { continue; } isHeader = false; if (line.startsWith(QLatin1String("#URL"))) { bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, QUrl(), QString(), getCurrentFolder()); type = UrlEntry; } else if (line.startsWith(QLatin1String("#FOLDER"))) { bookmark = BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), QString(), getCurrentFolder()); type = FolderStartEntry; } else if (line.startsWith(QLatin1String("#SEPERATOR"))) { bookmark = BookmarksManager::addBookmark(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder()); type = SeparatorEntry; } else if (line == QLatin1String("-")) { type = FolderEndEntry; } else if (line.startsWith(QLatin1String("\tURL=")) && bookmark) { const QUrl url(line.section(QLatin1Char('='), 1, -1)); if (!allowDuplicates() && BookmarksManager::hasBookmark(url)) { bookmark->remove(); bookmark = NULL; } else { bookmark->setData(url, BookmarksModel::UrlRole); } } else if (line.startsWith(QLatin1String("\tNAME=")) && bookmark) { bookmark->setData(line.section(QLatin1Char('='), 1, -1), BookmarksModel::TitleRole); } else if (line.startsWith(QLatin1String("\tDESCRIPTION=")) && bookmark) { bookmark->setData(line.section(QLatin1Char('='), 1, -1).replace(QLatin1String("\x02\x02"), QLatin1String("\n")), BookmarksModel::DescriptionRole); } else if (line.startsWith(QLatin1String("\tSHORT NAME=")) && bookmark) { const QString keyword(line.section(QLatin1Char('='), 1, -1)); if (!BookmarksManager::hasKeyword(keyword)) { bookmark->setData(keyword, BookmarksModel::KeywordRole); } } else if (line.startsWith(QLatin1String("\tCREATED=")) && bookmark) { bookmark->setData(QDateTime::fromTime_t(line.section(QLatin1Char('='), 1, -1).toUInt()), BookmarksModel::TimeAddedRole); } else if (line.startsWith(QLatin1String("\tVISITED=")) && bookmark) { bookmark->setData(QDateTime::fromTime_t(line.section(QLatin1Char('='), 1, -1).toUInt()), BookmarksModel::TimeVisitedRole); } else if (line.isEmpty()) { if (bookmark) { if (type == FolderStartEntry) { setCurrentFolder(bookmark); } bookmark = NULL; } else if (type == FolderEndEntry) { goToParent(); } type = NoEntry; } } file.close(); return true; }
bool StringArray::add(const char *pszEntry) { if (!pszEntry) return false; if (std::strlen(pszEntry) <= 0) return false; const uint16_t len = (uint16_t)std::strlen(pszEntry); // Can't add if full if (m_iNumEntries == m_iMaxEntries) { SCE_SLED_LOG(Logging::kError, "[SLED] Cannot add %s as StringArray is full!", pszEntry); return false; } // Can't add if longer than entry length if (len >= (m_iMaxEntryLen - 1)) { SCE_SLED_LOG(Logging::kError, "[SLED] Length of %s exceeds the maximum entry length - not adding!", pszEntry); return false; } const bool bCheckForDups = (allowDuplicates() == false); bool bFound = false; if ((m_iNumEntries != 0) && bCheckForDups) { // Search for duplicates for (uint16_t i = 0; (i < m_iNumEntries) && !bFound; i++) { // Slot is free so continue past if (m_pFreeList[i] == Slot::Free) continue; if (Utilities::areStringsEqual(operator[](i), pszEntry)) bFound = true; } } if (!bFound) { // Find spot to place item const uint16_t iFreeSlot = getFirstFreeSlotIndex(); SCE_SLED_ASSERT(iFreeSlot != (m_iMaxEntries + 1)); //const int32_t offset = m_iNumEntries++ * m_iMaxEntryLen; //char* pBuffer = reinterpret_cast< char* >(m_pBuffer) + offset; char *pBuffer = reinterpret_cast< char* >(m_pBuffer) + (iFreeSlot * m_iMaxEntryLen); Utilities::copyString(pBuffer, m_iMaxEntryLen, pszEntry); // Update counter ++m_iNumEntries; // Mark not free m_pFreeList[iFreeSlot] = Slot::Full; } return !bFound; }
void HtmlBookmarksImporter::processElement(const QWebElement &element) { if (element.tagName().toLower() == QLatin1String("h3")) { BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), element.toPlainText(), getCurrentFolder()); const QString keyword = element.attribute(QLatin1String("SHORTCUTURL")); if (!BookmarksManager::hasKeyword(keyword)) { bookmark->setData(keyword, BookmarksModel::KeywordRole); } if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty()) { const QDateTime time = QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt()); bookmark->setData(time, BookmarksModel::TimeAddedRole); bookmark->setData(time, BookmarksModel::TimeModifiedRole); } setCurrentFolder(bookmark); } else if (element.tagName().toLower() == QLatin1String("a")) { const QUrl url(element.attribute(QLatin1String("href"))); if (!allowDuplicates() && BookmarksManager::hasBookmark(url)) { return; } BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, url, element.toPlainText(), getCurrentFolder()); const QString keyword = element.attribute(QLatin1String("SHORTCUTURL")); if (!BookmarksManager::hasKeyword(keyword)) { bookmark->setData(keyword, BookmarksModel::KeywordRole); } if (element.parent().nextSibling().tagName().toLower() == QLatin1String("dd")) { bookmark->setData(element.parent().nextSibling().toPlainText(), BookmarksModel::DescriptionRole); } if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt()), BookmarksModel::TimeAddedRole); } if (!element.attribute(QLatin1String("LAST_MODIFIED")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_MODIFIED")).toUInt()), BookmarksModel::TimeModifiedRole); } if (!element.attribute(QLatin1String("LAST_VISITED")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_VISITED")).toUInt()), BookmarksModel::TimeVisitedRole); } } else if (element.tagName().toLower() == QLatin1String("hr")) { BookmarksManager::addBookmark(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder()); } const QWebElementCollection descendants = element.findAll(QLatin1String("*")); for (int i = 0; i < descendants.count(); ++i) { if (descendants.at(i).parent() == element) { processElement(descendants.at(i)); } } if (element.tagName().toLower() == QLatin1String("dl")) { goToParent(); } }
bool OperaBookmarksImporter::import() { QTextStream stream(m_file); stream.setCodec("UTF-8"); QString line = stream.readLine(); if (line != QLatin1String("Opera Hotlist version 2.0")) { return false; } BookmarksItem *bookmark = NULL; OperaBookmarkEntry type = NoEntry; bool isHeader = true; handleOptions(); while (!stream.atEnd()) { line = stream.readLine(); if (isHeader && (line.isEmpty() || line.at(0) != QLatin1Char('#'))) { continue; } isHeader = false; if (line.startsWith(QLatin1String("#URL"))) { bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, QUrl(), QString(), getCurrentFolder()); type = UrlEntry; } else if (line.startsWith(QLatin1String("#FOLDER"))) { bookmark = BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), QString(), getCurrentFolder()); type = FolderStartEntry; } else if (line.startsWith(QLatin1String("#SEPERATOR"))) { bookmark = BookmarksManager::addBookmark(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder()); type = SeparatorEntry; } else if (line == QLatin1String("-")) { type = FolderEndEntry; } else if (line.startsWith(QLatin1String("\tURL=")) && bookmark) { const QUrl url(line.section(QLatin1Char('='), 1, -1)); if (!allowDuplicates() && BookmarksManager::hasBookmark(url)) { bookmark->remove(); bookmark = NULL; } else { bookmark->setData(url, BookmarksModel::UrlRole); } } else if (line.startsWith(QLatin1String("\tNAME=")) && bookmark) { bookmark->setData(line.section(QLatin1Char('='), 1, -1), BookmarksModel::TitleRole); } else if (line.startsWith(QLatin1String("\tDESCRIPTION=")) && bookmark) { bookmark->setData(line.section(QLatin1Char('='), 1, -1).replace(QLatin1String("\x02\x02"), QLatin1String("\n")), BookmarksModel::DescriptionRole); } else if (line.startsWith(QLatin1String("\tSHORT NAME=")) && bookmark) { const QString keyword = line.section(QLatin1Char('='), 1, -1); if (!BookmarksManager::hasKeyword(keyword)) { bookmark->setData(keyword, BookmarksModel::KeywordRole); } } else if (line.startsWith(QLatin1String("\tCREATED=")) && bookmark) { bookmark->setData(QDateTime::fromTime_t(line.section(QLatin1Char('='), 1, -1).toUInt()), BookmarksModel::TimeAddedRole); } else if (line.startsWith(QLatin1String("\tVISITED=")) && bookmark) { bookmark->setData(QDateTime::fromTime_t(line.section(QLatin1Char('='), 1, -1).toUInt()), BookmarksModel::TimeVisitedRole); } else if (line.isEmpty()) { if (bookmark) { if (type == FolderStartEntry) { setCurrentFolder(bookmark); } bookmark = NULL; } else if (type == FolderEndEntry) { goToParent(); } type = NoEntry; } } return true; }
PlaylistBrowserNS::DynamicCategory::DynamicCategory( QWidget* parent ) : BrowserCategory( "dynamic category", parent ) { setPrettyName( i18n( "Dynamic Playlists" ) ); setShortDescription( i18n( "Dynamically updating parameter based playlists" ) ); setIcon( KIcon( "dynamic-amarok" ) ); setLongDescription( i18n( "With a dynamic playlist, Amarok becomes your own personal dj, automatically selecting tracks for you, based on a number of parameters that you select." ) ); setImagePath( KStandardDirs::locate( "data", "amarok/images/hover_info_dynamic_playlists.png" ) ); // set background if( AmarokConfig::showBrowserBackgroundImage() ) setBackgroundImage( imagePath() ); bool enabled = AmarokConfig::dynamicMode(); setContentsMargins( 0, 0, 0, 0 ); KHBox* controls2Layout = new KHBox( this ); QLabel *label; label = new QLabel( i18n( "Previous:" ), controls2Layout ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); m_previous = new QSpinBox( controls2Layout ); m_previous->setMinimum( 0 ); m_previous->setToolTip( i18n( "Number of previous tracks to remain in the playlist." ) ); m_previous->setValue( AmarokConfig::previousTracks() ); QObject::connect( m_previous, SIGNAL(valueChanged(int)), this, SLOT(setPreviousTracks(int)) ); label = new QLabel( i18n( "Upcoming:" ), controls2Layout ); // label->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ); label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); m_upcoming = new QSpinBox( controls2Layout ); m_upcoming->setMinimum( 1 ); m_upcoming->setToolTip( i18n( "Number of upcoming tracks to add to the playlist." ) ); m_upcoming->setValue( AmarokConfig::upcomingTracks() ); QObject::connect( m_upcoming, SIGNAL(valueChanged(int)), this, SLOT(setUpcomingTracks(int)) ); QObject::connect( (const QObject*)Amarok::actionCollection()->action( "playlist_clear" ), SIGNAL(triggered(bool)), this, SLOT(playlistCleared()) ); QObject::connect( (const QObject*)Amarok::actionCollection()->action( "disable_dynamic" ), SIGNAL(triggered(bool)), this, SLOT(playlistCleared()), Qt::DirectConnection ); // -- the tool bar KHBox* presetLayout = new KHBox( this ); KToolBar* presetToolbar = new KToolBar( presetLayout ); presetToolbar->setIconSize( QSize( 22, 22 ) ); presetToolbar->setToolButtonStyle( Qt::ToolButtonIconOnly ); presetToolbar->setMovable( false ); presetToolbar->setFloatable( false ); presetToolbar->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); m_onOffButton = new QToolButton( presetToolbar ); m_onOffButton->setText( i18nc( "Turn dynamic mode on", "On") ); m_onOffButton->setCheckable( true ); m_onOffButton->setIcon( KIcon( "dynamic-amarok" ) ); m_onOffButton->setToolTip( i18n( "Turn dynamic mode on." ) ); presetToolbar->addWidget( m_onOffButton ); m_duplicateButton = new QToolButton( presetToolbar ); m_duplicateButton->setText( i18n("Duplicates") ); m_duplicateButton->setCheckable( true ); m_duplicateButton->setChecked( allowDuplicates() ); m_duplicateButton->setIcon( KIcon( "edit-copy" ) ); m_duplicateButton->setToolTip( i18n( "Allow duplicate songs in result" ) ); presetToolbar->addWidget( m_duplicateButton ); m_addButton = new QToolButton( presetToolbar ); m_addButton->setText( i18n("New") ); m_addButton->setIcon( KIcon( "document-new" ) ); m_addButton->setToolTip( i18n( "New playlist" ) ); presetToolbar->addWidget( m_addButton ); m_editButton = new QToolButton( presetToolbar ); m_editButton->setText( i18n("Edit") ); m_editButton->setIcon( KIcon( "document-properties-amarok" ) ); m_editButton->setToolTip( i18n( "Edit the selected playlist or bias" ) ); presetToolbar->addWidget( m_editButton ); m_deleteButton = new QToolButton( presetToolbar ); m_deleteButton->setText( i18n("Delete") ); m_deleteButton->setEnabled( false ); m_deleteButton->setIcon( KIcon( "edit-delete" ) ); m_deleteButton->setToolTip( i18n( "Delete the selected playlist or bias") ); presetToolbar->addWidget( m_deleteButton ); m_repopulateButton = new QPushButton( presetLayout ); m_repopulateButton->setText( i18n("Repopulate") ); m_repopulateButton->setToolTip( i18n("Replace the upcoming tracks with fresh ones.") ); m_repopulateButton->setIcon( KIcon( "view-refresh-amarok" ) ); m_repopulateButton->setEnabled( enabled ); // m_repopulateButton->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); QObject::connect( m_repopulateButton, SIGNAL(clicked(bool)), The::playlistActions(), SLOT(repopulateDynamicPlaylist()) ); // -- the tree view m_tree = new DynamicView( this ); connect( m_tree->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged()) ); connect( m_onOffButton, SIGNAL(toggled(bool)), The::playlistActions(), SLOT(enableDynamicMode(bool)) ); connect( m_duplicateButton, SIGNAL(toggled(bool)), this, SLOT(setAllowDuplicates(bool)) ); connect( m_addButton, SIGNAL(clicked(bool)), m_tree, SLOT(addPlaylist()) ); connect( m_editButton, SIGNAL(clicked(bool)), m_tree, SLOT(editSelected()) ); connect( m_deleteButton, SIGNAL(clicked(bool)), m_tree, SLOT(removeSelected()) ); navigatorChanged(); selectionChanged(); connect( The::playlistActions(), SIGNAL(navigatorChanged()), this, SLOT(navigatorChanged()) ); }