Ejemplo n.º 1
0
//----< search the catalog for specific patterns >--------------------------
void Catalogue::searchCatalog(const std::string key, std::vector<std::string> list){
	DataStore::iterator iter = store_.begin();
	for (iter = store_.begin(); iter != store_.end(); iter++)
	{
		std::string filename = iter->first;
		std::string extension = FileSystem::Path::getExt(filename);

		for (auto patterns : list) {
			std::string temp = patterns;
			std::size_t found = patterns.find("*");
			if (found != std::string::npos) {
				if (patterns.size() > 2) {
					std::string patt = patterns.substr(found + 2);
					if (patt.find("*") != std::string::npos) {
						findPaths(iter->second, filename, key);
					}
					else if (patt == extension) {
						findPaths(iter->second, filename, key);
					}
				}
			}
			else if (filename == patterns) {
				findPaths(iter->second, filename, key);
			}
		}
	}
}
 void findPaths(TreeNode* root, string path, vector<string> &result) {
     if(!root) return;
     if(!root->left && !root->right)
     {
         result.push_back(path + to_string(root->val));
         return;
     }
     
     string next_path = path + to_string(root->val) + "->";
     findPaths(root->left, next_path, result);
     findPaths(root->right, next_path, result);
 }
Ejemplo n.º 3
0
 void findPaths( vector<int>& path, vector<vector<int>>& pathVec, TreeNode* root, int sum ) {
     path.push_back( root->val );
     if( !root->left && !root->right ) {
         if( root->val == sum ) pathVec.push_back( path );
     }
     else {
         sum -= root->val;
         if( root->left  ) findPaths( path, pathVec, root->left, sum );    
         if( root->right ) findPaths( path, pathVec, root->right, sum );
     }
     path.pop_back();
     return;
 }
Ejemplo n.º 4
0
 void findPaths(TreeNode * parent, std::vector<std::string> & result,
                std::string currentPath) const {
     if (!parent) { return; }
     if (currentPath.empty()) {
         currentPath += std::to_string(parent->val);
     } else {
         currentPath += "->" + std::to_string(parent->val);
     }
     findPaths(parent->left, result, currentPath);
     findPaths(parent->right, result, currentPath);
     if (!parent->left && !parent->right) { // Is leaf
         if (!currentPath.empty()) { result.push_back(currentPath); }
     }
 }
Ejemplo n.º 5
0
 void printLeafPaths() const {
     std::vector<std::string> result;
     findPaths(root, result, "");
     for (auto path : result) {
         std::cout << path << std::endl;
     }
 }
Ejemplo n.º 6
0
void MainWindow::itemSelected()
{
    auto selection = ui->tableView->selectionModel();
    auto message = ui->tableView->message(selection->currentIndex().row());
    if (message)
    {
        QList<PathRec> paths;
        auto text = message->originalMessage.toHtmlEscaped();
        findPaths(text, paths);
        for (int i = paths.size() - 1; i >= 0; --i)
        {
            auto& rec = paths[i];
            text.insert(rec.start + rec.length, "</a>");
            text.insert(rec.start, QString("<a href=\"%1\">").arg(rec.path.toHtmlEscaped()));
        }
        if (m_monospaceFont)
        {
            ui->messageText->setHtml("<pre>" + text + "</pre>");
        }
        else
        {
            ui->messageText->setHtml(text.replace("\n", "<br/>"));
        }
    }
    else
    {
        ui->messageText->setPlainText("");
    }
}
Ejemplo n.º 7
0
int findDir(const char * startDir, const char * dirName, char * outputPath)
{
    char rootPath[500];
//      char parentPath[500];
    char pathsFound[10][500];
    getRootPath(rootPath, 500);
    // fprintf(stderr, "finding number of possible dirs...\n");
    int numPossibleDirs = findPaths(startDir, pathsFound);
    // fprintf(stderr, "numPossibleDirs: %d\n", numPossibleDirs);

    if(numPossibleDirs ==0) return 0;

    int val;
    for(int i=numPossibleDirs-1; i >=0; i--)
        // for(int i=0; i<numPossibleDirs; i++)
    {
        val =findDirWithBase(pathsFound[i], dirName,outputPath);
        if(val == 1)
            return 1;
    }

    return 0;
//      printf("starting at %s and looking for %s\n", rootPath, startDir);
//      int val = gotoParent(startDir, parentPath);


//      printf("found base: %s\n", parentPath);
    //   return findDirWithBase(parentPath, dirName,outputPath);
}//end int findDir(char * startDir, char * dirName, char * outputPath)
Ejemplo n.º 8
0
void MainWindow::addTorrent() {
    QString torrent = QFileDialog::getOpenFileName(fake, QString(), QString(),
                                                   QString("*.torrent"));
    if (QFile(torrent).exists() || isMagnet(torrent))
        findPaths(torrent);
    else
        die("User don't choose torrent file");
}
Ejemplo n.º 9
0
 vector<vector<int> > pathSum(TreeNode *root, int sum) {
     vector<vector<int>> pathVec;
     vector<int> path;
     if( !root ) return pathVec;
     
     findPaths( path, pathVec, root, sum );
     
     return pathVec;
 }
Ejemplo n.º 10
0
MainWindow::MainWindow(QString torrent, QString downloadPath, QString mountPath, QString rate, bool gui, QObject *parent): QObject(parent) {
    initSession(rate);
    initscr();
    nodelay(stdscr, true);
    noecho();
    main = NULL;
    if (!gui)
        realAddTorrent(torrent, downloadPath, mountPath);
    else {
        fake = new QMainWindow;
        if (QFile(torrent).exists() || isMagnet(torrent))
            findPaths(torrent);
        else
            addTorrent();
    }
}
Ejemplo n.º 11
0
int findFile(const char * startDir, const char * fileName, char * outputPath)
{
    char rootPath[500];
//      char parentPath[500];
    char pathsFound[10][500];
    getRootPath(rootPath, 500);
    int numPossibleDirs = findPaths(startDir, pathsFound);

    if(numPossibleDirs ==0) return 0;

    int val;
    for(int i=0; i<numPossibleDirs; i++)
    {
        val =findFileWithBase(pathsFound[i], fileName,outputPath);
        if(val == 1)
            return 1;
    }

    return 0;
}//end int findFile(char * startDir, char * fileName, char * outputPath)
Ejemplo n.º 12
0
void MainWindow::itemMenu(QPoint pos)
{
    QMenu* menu = new QMenu(this);

    auto selection = ui->tableView->selectionModel();
    auto message = ui->tableView->message(selection->currentIndex().row());
    if (message)
    {
        QList<PathRec> paths;
        auto text = message->originalMessage.toHtmlEscaped();
        findPaths(text, paths);
        for (int i = 0; i < paths.size(); ++i)
        {
            menu->addAction(paths[i].path, this, "uurlClicked()");
        }
        if (paths.size())
        {
            menu->addSeparator();
        }
        if (auto logModel = dynamic_cast<LogModel*>(ui->tableView->sourceModel()))
        {
            LogModel::Client client;
            if (logModel->clientFromMessage(*message, client))
            {
                QFontMetrics metrics(menu->font());
                auto path = metrics.elidedText(client.path(), Qt::ElideMiddle, 200);
                auto name = QString("Disconnect [%1] %2").arg(client.pid()).arg(path);
                auto action = new QAction(name, this);
                action->setProperty("socket", quint64(client.socket()));
                connect(action, &QAction::triggered, this, &MainWindow::disconnectClient);
                menu->addAction(action);
                menu->addSeparator();
            }
        }
    }
    menu->addAction(ui->actionClear);
    menu->exec(ui->tableView->mapToGlobal(pos));
    delete menu;
}
 vector<string> binaryTreePaths(TreeNode* root) {
     vector<string> ans;
     findPaths(root, "", ans);
     return ans;
 }