void DirectoryListing::Directory::filterList(DirectoryListing& dirList) {
    DirectoryListing::Directory* d = dirList.getRoot();

    TTHSet l;
    d->getHashList(l);
    filterList(l);
}
Esempio n. 2
0
void Completer::complete(const QString& text, int selStart, int selEnd)
{
    if (text.isEmpty())
        return;

    int wordStart = 0, wordEnd = 0;
    const QString word = findWord(text, selStart, selEnd, &wordStart, &wordEnd);

    QStringList candidates;
    if (word == "/")
        candidates = CommandParser::availableCommands();
    else if (wordStart > 0 && text.at(wordStart - 1) == '/')
        candidates = filterList(CommandParser::availableCommands(), word);
    else
        candidates = filterList(m_item->users(), word);

    if (m_candidates != candidates)
    {
        m_current = 0;
        m_candidates = candidates;
    }
    else
    {
        if (!m_candidates.isEmpty())
            m_current = (m_current + 1) % m_candidates.count();
        else
            m_current = 0;
    }

    if (!m_candidates.isEmpty())
    {
        QString replace = m_candidates.value(m_current);

        if (word == "/")
            ++wordStart;

        QString completion = text;
        completion.replace(wordStart, selEnd - wordStart, replace);
        emit completed(completion, selStart, wordStart + replace.length());
    }
}
Esempio n. 3
0
	std::set<std::string> VFS::listDirectories(const std::string& path, const std::string& filterregex) const {
		std::set<std::string> list = listDirectories(path);
		return filterList(list, filterregex);
	}
asynStatus FileList::updateList()
{
	char dirBase[INPUT_WAVEFORM_LIM];
	char search[INPUT_WAVEFORM_LIM];
	int caseSense;
	std::list<std::string> files;
	int status = asynSuccess;
	std::string out;

	lock();

	//get all files in directory
	status |= getStringParam(P_DirBase, INPUT_WAVEFORM_LIM, dirBase);

	if (getFileList(dirBase, files) == -1)
	{
		std::cerr << "Directory not found: " << dirBase << std::endl;
		unlock();
		return asynError;
	}

	//search files
	status |= getStringParam(P_Search, INPUT_WAVEFORM_LIM, search);

	status |= getIntegerParam(P_CaseSensitive, &caseSense);

	if (caseSense == 0)
	{
		status |= filterList(files, std::string("(?i)").append(search));
	} else {
		status |= filterList(files, search);
	}
	
	if (m_fullPath)
	{
	    std::string dir_prefix = std::string(dirBase) + "/";
	    std::replace(dir_prefix.begin(), dir_prefix.end(), '\\', '/');
		for(std::list<std::string>::iterator it = files.begin(); it != files.end(); ++it)
		{
		    it->insert(0, dir_prefix);
		}
	}
	
	//add appropriate files to PV
	std::string tOut = json_list_to_array(files);
	status |= compressString(tOut, out);

	if (out.size() < OUT_CHAR_LIM)
		std::copy(out.begin(), out.end(), pJSONOut_);
	else
		std::cerr << "File list too long: " << out.size() << std::endl;

	status |= setStringParam(P_JSONOutArr, pJSONOut_);

	/* Do callbacks so higher layers see any changes */
	status |= (asynStatus)callParamCallbacks();

	unlock();

	return (asynStatus)status;
}
Esempio n. 5
0
void HighlightConfig::load()
{
    m_filters.clear(); //clear filters

    const QString filename = KStandardDirs::locateLocal( "appdata", QString::fromLatin1( "highlight.xml" ) );
    if( filename.isEmpty() )
        return ;

    QDomDocument filterList( QString::fromLatin1( "highlight-plugin" ) );

    QFile filterListFile( filename );
    filterListFile.open( QIODevice::ReadOnly );
    filterList.setContent( &filterListFile );

    QDomElement list = filterList.documentElement();

    QDomNode node = list.firstChild();
    while( !node.isNull() )
    {
        QDomElement element = node.toElement();
        if( !element.isNull() )
        {
//			if( element.tagName() == QString::fromLatin1("filter")
//			{
            Filter *filtre=newFilter();
            QDomNode filterNode = node.firstChild();

            while( !filterNode.isNull() )
            {
                QDomElement filterElement = filterNode.toElement();
                if( !filterElement.isNull() )
                {
                    if( filterElement.tagName() == QString::fromLatin1( "display-name" ) )
                    {
                        filtre->displayName = filterElement.text();
                    }
                    else if( filterElement.tagName() == QString::fromLatin1( "search" ) )
                    {
                        filtre->search = filterElement.text();

                        filtre->caseSensitive= ( filterElement.attribute( QString::fromLatin1( "caseSensitive" ), QString::fromLatin1( "1" ) ) == QString::fromLatin1( "1" ) );
                        filtre->isRegExp= ( filterElement.attribute( QString::fromLatin1( "regExp" ), QString::fromLatin1( "0" ) ) == QString::fromLatin1( "1" ) );
                    }
                    else if( filterElement.tagName() == QString::fromLatin1( "FG" ) )
                    {
                        filtre->FG = filterElement.text();
                        filtre->setFG= ( filterElement.attribute( QString::fromLatin1( "set" ), QString::fromLatin1( "0" ) ) == QString::fromLatin1( "1" ) );
                    }
                    else if( filterElement.tagName() == QString::fromLatin1( "BG" ) )
                    {
                        filtre->BG = filterElement.text();
                        filtre->setBG= ( filterElement.attribute( QString::fromLatin1( "set" ), QString::fromLatin1( "0" ) ) == QString::fromLatin1( "1" ) );
                    }
                    else if( filterElement.tagName() == QString::fromLatin1( "importance" ) )
                    {
                        filtre->importance = filterElement.text().toUInt();
                        filtre->setImportance= ( filterElement.attribute( QString::fromLatin1( "set" ), QString::fromLatin1( "0" ) ) == QString::fromLatin1( "1" ) );
                    }
                    else if( filterElement.tagName() == QString::fromLatin1( "raise" ) )
                    {
                        filtre->raiseView = ( filterElement.attribute( QString::fromLatin1( "set" ), QString::fromLatin1( "0" ) ) == QString::fromLatin1( "1" ) );
                    }
                }
                filterNode = filterNode.nextSibling();
            }
//			}
        }
        node = node.nextSibling();
    }
    filterListFile.close();
}
Esempio n. 6
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow) {
  ui->setupUi(this);

  QFile styleFile(":/style.css");
  styleFile.open(QFile::ReadOnly);
  QString styleSheet = QLatin1String(styleFile.readAll());
  qApp->setStyleSheet(styleSheet);

  QPixmap window_icon;
  QFile iconFile(":/icon.png");
  iconFile.open(QFile::ReadOnly);
  QByteArray icon_data = iconFile.readAll();
  window_icon.loadFromData(icon_data);
  qApp->setWindowIcon(QIcon(window_icon));

  awesome = new QtAwesome(qApp);
  settings = new Settings(this);
  window_watcher = new WindowWatcher(this);
  anitomy = new AnitomyWrapper();
  event_timer = new QTimer(this);
  watch_timer = new QTimer(this);
  uptime_timer = new QElapsedTimer;
  progress_bar = new QProgressBar(ui->statusBar);
  over = new Overlay(this);
  torrent_refresh_time = 0;
  user_refresh_time =
      settings->getValue(Settings::UserRefreshTime, D_USER_REFRESH_TIME)
          .toInt();
  download_rule = 0;
  download_count = 0;
  hasUser = false;

  uptime_timer->start();
  watch_timer->setSingleShot(true);

  awesome->initFontAwesome();

  bool check_for_updates =
      settings->getValue(Settings::CheckUpdates, D_CHECK_FOR_UPDATES).toBool();

  if (check_for_updates) {
    connect(FvUpdater::sharedUpdater(), &FvUpdater::restartRequested,
            [&]() {  // NOLINT
              QString app = QApplication::applicationFilePath();
              QStringList arguments = QApplication::arguments();
              QString wd = QDir::currentPath();
              QProcess::startDetached(app, arguments, wd);
              elegantClose(true);
            });

    FvUpdater::sharedUpdater()->CheckForUpdatesSilent();
  }

  QFont font = ui->listTabs->tabBar()->font();
  font.setCapitalization(QFont::Capitalize);
  ui->listTabs->tabBar()->setFont(font);

  int currentYear = QDate::currentDate().year();
  int lowerYear = currentYear - 10;

  while (currentYear > lowerYear) {
    ui->comboYear->addItem(QString::number(currentYear));
    currentYear--;
  }

  QWidget *container = new QWidget(ui->scrollArea);
  layout = new FlowLayout(container);
  ui->scrollArea->setWidget(container);
  container->setLayout(layout);

  QWidget *container2 = new QWidget(ui->scrollArea_2);
  layout2 = new FlowLayout(container2);
  layout2->disableSort();
  ui->scrollArea_2->setWidget(container2);
  container2->setLayout(layout2);

  QVariantMap black;
  black.insert("color", QColor(0, 0, 0));
  black.insert("color-active", QColor(0, 0, 0));
  black.insert("color-disabled", QColor(0, 0, 0));
  black.insert("color-selected", QColor(0, 0, 0));

  ui->airingButton->setIcon(awesome->icon(fa::clocko, black));
  ui->torrentsButton->setIcon(awesome->icon(fa::rss, black));
  ui->animeButton->setIcon(awesome->icon(fa::bars, black));
  ui->seasonsButton->setIcon(awesome->icon(fa::th, black));
  ui->statisticsButton->setIcon(awesome->icon(fa::piechart, black));

  ui->tabWidget->tabBar()->hide();
  ui->tabWidget->setCurrentIndex(UserTabs::tAnime);
  ui->listTabs->setCurrentIndex(0);

  ui->statusBar->addWidget(progress_bar);
  ui->statusBar->layout()->setContentsMargins(1, 0, 0, 0);
  progress_bar->setRange(0, 100);
  progress_bar->setValue(5);
  progress_bar->setFormat("Authorizing");

  QSettings s;
  restoreGeometry(s.value("mainWindowGeometry").toByteArray());
  restoreState(s.value("mainWindowState").toByteArray());

  connect(&user_future_watcher, SIGNAL(finished()), SLOT(userLoaded()));
  connect(&user_list_future_watcher, SIGNAL(finished()),
          SLOT(userListLoaded()));

  connect(ui->animeButton, SIGNAL(clicked()), SLOT(showAnimeTab()));
  connect(ui->airingButton, SIGNAL(clicked()), SLOT(showAiringTab()));
  connect(ui->torrentsButton, SIGNAL(clicked()), SLOT(showTorrentsTab()));
  connect(ui->seasonsButton, SIGNAL(clicked()), SLOT(showBrowseTab()));
  connect(ui->actionSettings, SIGNAL(triggered()), SLOT(showSettings()));
  connect(ui->statisticsButton, SIGNAL(clicked()), SLOT(showStatisticsTab()));

  connect(ui->actionExit, &QAction::triggered, [&, this]() {  // NOLINT
    this->elegantClose();
  });

  connect(ui->actionAbout, &QAction::triggered, [&, this]() {  // NOLINT
    About *about = new About(this);
    about->show();
  });

  connect(ui->actionHelp, &QAction::triggered, [&, this]() {  // NOLINT
    QDesktopServices::openUrl(QUrl("http://app.shinjiru.me/support.php"));
  });

  connect(ui->actionRL, &QAction::triggered, [&, this]() {  // NOLINT
    loadUser();
  });

  connect(ui->actionAS, &QAction::triggered, [&]() {  // NOLINT
    SearchPanel *sp = new SearchPanel(this);
    sp->show();
  });

  connect(ui->actionARR, &QAction::triggered, [&, this]() {  // NOLINT
    SettingsDialog *s = new SettingsDialog(this);
    s->showSmartTitles();

    connect(s, &QDialog::accepted, [&, this]() {  // NOLINT
      Settings set;

      toggleAnimeRecognition(
          set.getValue(Settings::AnimeRecognitionEnabled, D_ANIME_RECOGNITION)
              .toBool());

      torrents_enabled =
          set.getValue(Settings::TorrentsEnabled, D_TORRENTS_ENABLED).toBool();

      reloadSmartTitles();
      reloadRules();
    });
  });

  connect(qApp, SIGNAL(aboutToQuit()), SLOT(elegantClose()));

  connect(ui->actionVAL, SIGNAL(triggered()), SLOT(viewAnimeList()));
  connect(ui->actionVD, SIGNAL(triggered()), SLOT(viewDashboard()));
  connect(ui->actionVP, SIGNAL(triggered()), SLOT(viewProfile()));
  connect(ui->actionEAR, SIGNAL(triggered(bool)),
          SLOT(toggleAnimeRecognition(bool)));
  connect(ui->actionExport, SIGNAL(triggered()), SLOT(exportListJSON()));
  connect(ui->actionUpdate, SIGNAL(triggered()), FvUpdater::sharedUpdater(),
          SLOT(CheckForUpdatesNotSilent()));

  connect(window_watcher, SIGNAL(title_found(QString)), SLOT(watch(QString)));
  connect(watch_timer, SIGNAL(timeout()), SLOT(updateEpisode()));
  connect(event_timer, SIGNAL(timeout()), SLOT(eventTick()));

  connect(ui->torrentTable, SIGNAL(customContextMenuRequested(QPoint)),
          SLOT(torrentContextMenu(QPoint)));
  connect(ui->torrentFilter, SIGNAL(textChanged(QString)),
          SLOT(filterTorrents(QString)));
  connect(ui->chkHideUnknown, SIGNAL(toggled(bool)),
          SLOT(filterTorrents(bool)));
  connect(ui->refreshButton, SIGNAL(clicked()), SLOT(refreshTorrentListing()));

  connect(ui->actionEAR, SIGNAL(toggled(bool)), SLOT(applyEAR()));

  connect(ui->tabWidget, &QTabWidget::currentChanged, [&, this](  // NOLINT
                                                          int tab) {
    if (tab != 0) {
      this->over->removeDrawing("blank_table");
      this->over->removeDrawing("no anime");
      ui->listTabs->show();
      ui->listFilterLineEdit->show();
    } else {
      this->filterList(3);

      if (hasUser && (User::sharedUser()->getAnimeList().count() == 0)) {
        this->addNoAnimePrompt();
      }
    }
  });

  ui->actionEAR->setChecked(
      settings->getValue(Settings::AnimeRecognitionEnabled, D_ANIME_RECOGNITION)
          .toBool());

  this->toggleAnimeRecognition(ui->actionEAR->isChecked());

  QString genrelist =
      "Action, Adult, Adventure, Cars, Comedy, Dementia, Demons, Doujinshi, "
      "Drama, Ecchi, Fantasy, Game, Gender Bender, Harem, Hentai, Historical, "
      "Horror, Josei, Kids, Magic, Martial Arts, Mature, Mecha, Military, "
      "Motion Comic, Music, Mystery, Mythological , Parody, Police, "
      "Psychological, Romance, Samurai, School, Sci-Fi, Seinen, Shoujo, Shoujo "
      "Ai, Shounen, Shounen Ai, Slice of Life, Space, Sports, Super Power, "
      "Supernatural, Thriller, Tragedy, Vampire, Yaoi, Yuri";
  QStringList genres = genrelist.split(", ");

  for (QString genre : genres) {
    QCheckBox *chk = new QCheckBox();

    chk->setText(genre);
    chk->setTristate(true);

    ui->genreList->addWidget(chk);
  }

  connect(ui->listFilterLineEdit, SIGNAL(textChanged(QString)),
          SLOT(filterList(QString)));
  connect(ui->listFilterLineEdit, SIGNAL(returnPressed()), SLOT(showSearch()));
  connect(ui->listTabs, SIGNAL(currentChanged(int)), SLOT(filterList(int)));

  connect(ui->browseButton, SIGNAL(clicked()), SLOT(loadBrowserData()));

  this->show();
  createActions();
  initTray();
  trayIcon->show();

  int result = API::sharedAPI()->verifyAPI();

  if (result == AniListAPI::OK) {
    connect(API::sharedAPI()->sharedAniListAPI(), &AniListAPI::access_granted,
            [&, this]() {  // NOLINT
              progress_bar->setValue(10);
              progress_bar->setFormat("Access granted");
              loadUser();

              event_timer->start(1000);
            });

    connect(API::sharedAPI()->sharedAniListAPI(), &AniListAPI::access_denied,
            [&, this](QString error) {  // NOLINT
              qCritical() << error;

              if (isVisible()) {
                QMessageBox::critical(this, "Shinjiru", tr("Error: ") + error);
              }
            });
  } else if (result == AniListAPI::NO_CONNECTION) {
    qDebug() << "Starting Shinjiru in offline mode";
    hasUser = User::sharedUser()->loadLocal();
  }

  reloadRules();
}
Esempio n. 7
0
MainWindow::MainWindow()
: KXmlGuiWindow()
{
    QWidget* mainWidget = new QWidget;
    setCentralWidget( mainWidget );

    QVBoxLayout* layout = new QVBoxLayout;
    layout->setMargin( 0 );
    layout->setSpacing( 0 );
    mainWidget->setLayout( layout );

    m_searchEdit = new KLineEdit;
    m_searchEdit->setClearButtonShown( true );
    m_searchEdit->setClickMessage( i18n( "Type here to start searching..." ) );
    layout->addWidget( m_searchEdit );

    m_listView = new QListView;
    m_proxyModel = new QSortFilterProxyModel( this );
    m_listModel = new CleanerModel( this );
    m_proxyModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
    m_proxyModel->setSortRole( Qt::UserRole );
    m_proxyModel->setSourceModel( m_listModel );
    m_listView->setSelectionMode( QAbstractItemView::NoSelection );
    m_listView->setUniformItemSizes( true );
    m_listView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    m_listView->setModel( m_proxyModel );
    layout->addWidget( m_listView );

    QHBoxLayout* buttonLayout = new QHBoxLayout;
    buttonLayout->setMargin( 0 );
    buttonLayout->setSpacing( 0 );
    layout->addLayout( buttonLayout );

    m_refreshButton = new KPushButton( i18n( "Refresh" ) );
    m_refreshButton->setIcon( KIcon( "view-refresh" ) );
    buttonLayout->addWidget( m_refreshButton );
    connect( m_refreshButton, SIGNAL(clicked()), m_listModel, SLOT(refresh()) );

    m_cleanupButton = new KPushButton( i18n( "Clean up..." ) );
    m_cleanupButton->setIcon( KIcon( "edit-clear" ) );
    buttonLayout->addWidget( m_cleanupButton );
    connect( m_cleanupButton, SIGNAL(clicked()), m_listModel, SLOT(saolaji()) );

    m_cancelProfileButton = new KPushButton( i18n( "Cancel" ) );
    buttonLayout->addWidget( m_cancelProfileButton );
    connect( m_cancelProfileButton, SIGNAL(clicked()), this, SLOT(cancelProfile()) );

    m_saveProfileButton = new KPushButton( i18n( "Save" ) );
    buttonLayout->addWidget( m_saveProfileButton );
    connect( m_saveProfileButton, SIGNAL(clicked()), this, SLOT(saveProfile()) );

    m_cancelProfileButton->hide();
    m_saveProfileButton->hide();
    m_editingProfile = 0;

    KAction* knsDownloadAction = actionCollection()->addAction( "kns_download" );
    knsDownloadAction->setText( i18n( "&Download scripts..." ) );
    knsDownloadAction->setIcon( KIcon( "get-hot-new-stuff" ) );
    connect( knsDownloadAction, SIGNAL(triggered()), this, SLOT(knsDownload()) );

    KAction* newProfileAction = actionCollection()->addAction( "new_profile" );
    newProfileAction->setText( i18n( "New profile..." ) );
    newProfileAction->setIcon( KIcon( "bookmark-new" ) );
    connect( newProfileAction, SIGNAL(triggered()), this, SLOT(newProfile()) );

    connect( m_searchEdit, SIGNAL(textChanged(QString)), this, SLOT(filterList(QString)) );
    connect( m_listModel, SIGNAL(refreshFinished()), this, SLOT(sortList()) );

    KStandardAction::selectAll( m_listModel, SLOT(selectAll()), actionCollection() );
    KStandardAction::deselect( m_listModel, SLOT(deselect()), actionCollection() );
    KStandardAction::quit( this, SLOT(close()), actionCollection() );

    setupGUI( KXmlGuiWindow::Keys | KXmlGuiWindow::Save | KXmlGuiWindow::Create );

    m_selectProfileSignalMapper = new QSignalMapper( this );
    connect( m_selectProfileSignalMapper, SIGNAL(mapped(QObject*)),
             this, SLOT(selectProfile(QObject*)) );
    m_editProfileSignalMapper = new QSignalMapper( this );
    connect( m_editProfileSignalMapper, SIGNAL(mapped(QObject*)),
             this, SLOT(editProfile(QObject*)) );
    m_deleteProfileSignalMapper = new QSignalMapper( this );
    connect( m_deleteProfileSignalMapper, SIGNAL(mapped(QObject*)),
             this, SLOT(deleteProfile(QObject*)) );

    QTimer::singleShot( 0, this, SLOT(setupProfileActions()) );
}
Esempio n. 8
0
File: vfs.cpp Progetto: m64/PEG
	std::set<std::string> VFS::listFiles(const std::string& path, const std::string& filterregex) const {
		std::string lowerpath = lower(path);
		std::set<std::string> list = listFiles(lowerpath);
		return filterList(list, filterregex);
	}