From 622914c923f47af4c041d002b4643141e7612ff0 Mon Sep 17 00:00:00 2001 From: defnax Date: Wed, 20 Aug 2008 21:39:03 +0000 Subject: [PATCH] * removed old config path * added FindWindow for Library Dialog * Fixed Cancel Button of ShareFiles git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@702 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/RetroShare.pro | 8 +- retroshare-gui/src/config/rsharesettings.cpp | 272 ------------------ retroshare-gui/src/config/rsharesettings.h | 140 --------- retroshare-gui/src/gui/LibraryDialog.cpp | 27 +- retroshare-gui/src/gui/LibraryDialog.h | 5 +- retroshare-gui/src/gui/LibraryDialog.ui | 19 +- retroshare-gui/src/gui/ShareFilesDialog.ui | 14 +- retroshare-gui/src/gui/library/FindWindow.cpp | 201 +++++++++++++ retroshare-gui/src/gui/library/FindWindow.h | 64 +++++ 9 files changed, 321 insertions(+), 429 deletions(-) delete mode 100644 retroshare-gui/src/config/rsharesettings.cpp delete mode 100644 retroshare-gui/src/config/rsharesettings.h create mode 100644 retroshare-gui/src/gui/library/FindWindow.cpp create mode 100644 retroshare-gui/src/gui/library/FindWindow.h diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 60c037804..fb2b107a6 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -14,7 +14,6 @@ TARGET += DEPENDPATH += . \ rsiface \ - config \ control \ gui \ lang \ @@ -25,7 +24,8 @@ DEPENDPATH += . \ gui\connect \ gui\images \ gui\Preferences \ - gui\common\ + gui\common \ + gui\library \ gui\Settings \ gui\toaster \ gui\help\browser \ @@ -106,6 +106,7 @@ HEADERS += rshare.h \ gui/connect/InviteDialog.h \ gui/connect/AddFriendDialog.h \ gui/connect/AddFriendWizard.h \ + gui/library/FindWindow.h \ gui/msgs/ChanMsgDialog.h \ gui/msgs/ChanCreateDialog.h \ gui/images/retroshare_win.rc.h \ @@ -331,7 +332,8 @@ SOURCES += main.cpp \ gui/Preferences/rsettings.cpp \ gui/common/vmessagebox.cpp \ gui/common/rwindow.cpp \ - gui/common/html.cpp \ + gui/common/html.cpp \ + gui/library/FindWindow.cpp \ gui/Settings/gsettingswin.cpp \ gui/Settings/GeneralPage.cpp \ gui/Settings/DirectoriesPage.cpp \ diff --git a/retroshare-gui/src/config/rsharesettings.cpp b/retroshare-gui/src/config/rsharesettings.cpp deleted file mode 100644 index b2debe992..000000000 --- a/retroshare-gui/src/config/rsharesettings.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/**************************************************************** - * This file is distributed under the following license: - * - * Copyright (c) 2006-2007, crypton - * Copyright (c) 2006, Matt Edman, Justin Hipple - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - ****************************************************************/ - - - -#include -#include -#include -#include -#include - -#include "rsharesettings.h" - -#include -#include - -#if defined(Q_WS_WIN) -#include -#include -#endif - - -/* Retroshare's Settings */ -#define SETTING_LANGUAGE "LanguageCode" -#define SETTING_STYLE "InterfaceStyle" -#define SETTING_SHEETNAME "SheetName" - -#define SETTING_DATA_DIRECTORY "DataDirectory" -#define SETTING_SHOW_MAINWINDOW_AT_START "ShowMainWindowAtStart" -#define SETTING_BWGRAPH_FILTER "StatisticDialog/BWLineFilter" -#define SETTING_BWGRAPH_OPACITY "StatisticDialog/Opacity" -#define SETTING_BWGRAPH_ALWAYS_ON_TOP "StatisticDialog/AlwaysOnTop" - -/* Default Retroshare Settings */ -#define DEFAULT_OPACITY 100 - - -#if defined(Q_OS_WIN32) -#define STARTUP_REG_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run" -#define Rshare_REG_KEY "RetroShare" -#endif - -/* Default bandwidth graph settings */ -#define DEFAULT_BWGRAPH_FILTER (BWGRAPH_SEND|BWGRAPH_REC) -#define DEFAULT_BWGRAPH_ALWAYS_ON_TOP false - - - -/** Default Constructor */ -RshareSettings::RshareSettings() -: QSettings(SETTINGS_FILE, QSettings::IniFormat) -{ -#if defined(Q_WS_MAC) - setDefault(SETTING_STYLE, "macintosh (aqua)"); -#else - static QStringList styles = QStyleFactory::keys(); -#if defined(Q_WS_WIN) - if (styles.contains("windowsvista", Qt::CaseInsensitive)) - setDefault(SETTING_STYLE, "windowsvista"); - else -#endif - { - if (styles.contains("cleanlooks", Qt::CaseInsensitive)) - setDefault(SETTING_STYLE, "cleanlooks"); - else - setDefault(SETTING_STYLE, "plastique"); - } -#endif - - setDefault(SETTING_LANGUAGE, LanguageSupport::defaultLanguageCode()); - setDefault(SETTING_SHEETNAME, true); - setDefault(SETTING_SHOW_MAINWINDOW_AT_START, true); -} - - -/** Gets the currently preferred language code for Rshare. */ -QString RshareSettings::getLanguageCode() -{ - return value(SETTING_LANGUAGE).toString(); -} - -/** Sets the preferred language code. */ -void RshareSettings::setLanguageCode(QString languageCode) -{ - setValue(SETTING_LANGUAGE, languageCode); -} - -/** Gets the interface style key (e.g., "windows", "motif", etc.) */ -QString RshareSettings::getInterfaceStyle() -{ - return value(SETTING_STYLE).toString(); -} - -/** Sets the interface style key. */ -void RshareSettings::setInterfaceStyle(QString styleKey) -{ - setValue(SETTING_STYLE, styleKey); -} - -/** Gets the sheetname.*/ -QString RshareSettings::getSheetName() -{ - return value(SETTING_SHEETNAME).toString(); -} -/** Sets the sheetname.*/ -void RshareSettings::setSheetName(QString sheet) -{ - setValue(SETTING_SHEETNAME, sheet); -} - -/** Returns the bandwidth line filter. */ -uint RshareSettings::getBWGraphFilter() -{ - return value(SETTING_BWGRAPH_FILTER, DEFAULT_BWGRAPH_FILTER).toUInt(); -} - -/** Saves the setting for whether or not the given line will be graphed */ -void RshareSettings::setBWGraphFilter(uint line, bool status) -{ - uint filter = getBWGraphFilter(); - filter = (status ? (filter | line) : (filter & ~(line))); - setValue(SETTING_BWGRAPH_FILTER, filter); -} - -/** Get the level of opacity for the BandwidthGraph window. */ -int RshareSettings::getBWGraphOpacity() -{ - return value(SETTING_BWGRAPH_OPACITY, DEFAULT_OPACITY).toInt(); -} - -/** Set the level of opacity for the BandwidthGraph window. */ -void RshareSettings::setBWGraphOpacity(int value) -{ - setValue(SETTING_BWGRAPH_OPACITY, value); -} - -/** Gets whether the bandwidth graph is always on top when displayed. */ -bool RshareSettings::getBWGraphAlwaysOnTop() -{ - return value(SETTING_BWGRAPH_ALWAYS_ON_TOP, - DEFAULT_BWGRAPH_ALWAYS_ON_TOP).toBool(); -} - -/** Sets whether the bandwidth graph is always on top when displayed. */ -void RshareSettings::setBWGraphAlwaysOnTop(bool alwaysOnTop) -{ - setValue(SETTING_BWGRAPH_ALWAYS_ON_TOP, alwaysOnTop); -} - -/** Returns true if RetroShare's main window should be visible when the - * application starts. */ -bool -RshareSettings::showMainWindowAtStart() -{ - return value(SETTING_SHOW_MAINWINDOW_AT_START).toBool(); -} - -/** Sets whether to show RetroShare's main window when the application starts. */ -void -RshareSettings::setShowMainWindowAtStart(bool show) -{ - setValue(SETTING_SHOW_MAINWINDOW_AT_START, show); -} - -/** Returns true if Vidalia is set to run on system boot. */ -bool -RshareSettings::runRetroshareOnBoot() -{ -#if defined(Q_WS_WIN) - if (!win32_registry_get_key_value(STARTUP_REG_KEY, Rshare_REG_KEY).isEmpty()) { - return true; - } else { - return false; - } -#else - /* Platforms other than windows aren't supported yet */ - return false; -#endif -} - -/** If run is set to true, then Vidalia will run on system boot. */ -void -RshareSettings::setRunRetroshareOnBoot(bool run) -{ -#if defined(Q_WS_WIN) - if (run) { - win32_registry_set_key_value(STARTUP_REG_KEY, Rshare_REG_KEY, - QString("\"" + - QDir::convertSeparators(QCoreApplication::applicationFilePath())) + - "\""); - } else { - win32_registry_remove_key(STARTUP_REG_KEY, Rshare_REG_KEY); - } -#else - /* Platforms othe rthan windows aren't supported yet */ - Q_UNUSED(run); - return; -#endif -} - -/** Saving Generic Widget Size / Location */ - -void RshareSettings::saveWidgetInformation(QWidget *widget) -{ - beginGroup("widgetInformation"); - beginGroup(widget->objectName()); - - setValue("size", widget->size()); - setValue("pos", widget->pos()); - - endGroup(); - endGroup(); -} - -void RshareSettings::saveWidgetInformation(QMainWindow *widget, QToolBar *toolBar) -{ - beginGroup("widgetInformation"); - beginGroup(widget->objectName()); - - setValue("toolBarArea", widget->toolBarArea(toolBar)); - - endGroup(); - endGroup(); - - saveWidgetInformation(widget); -} - -void RshareSettings::loadWidgetInformation(QWidget *widget) -{ - beginGroup("widgetInformation"); - beginGroup(widget->objectName()); - - widget->resize(value("size", widget->size()).toSize()); - widget->move(value("pos", QPoint(200, 200)).toPoint()); - - endGroup(); - endGroup(); -} - -void RshareSettings::loadWidgetInformation(QMainWindow *widget, QToolBar *toolBar) -{ - beginGroup("widgetInformation"); - beginGroup(widget->objectName()); - - widget->addToolBar((Qt::ToolBarArea) value("toolBarArea", Qt::TopToolBarArea).toInt(), - toolBar); - - endGroup(); - endGroup(); - - loadWidgetInformation(widget); -} - diff --git a/retroshare-gui/src/config/rsharesettings.h b/retroshare-gui/src/config/rsharesettings.h deleted file mode 100644 index efe59c202..000000000 --- a/retroshare-gui/src/config/rsharesettings.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************** - * This file is distributed under the following license: - * - * Copyright (c) 2006-2007, crypton - * Copyright (c) 2006, Matt Edman, Justin Hipple - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - ****************************************************************/ - - - -#ifndef _RSHARESETTINGS_H -#define _RSHARESETTINGS_H - -#include -#include - -#include - - -//Forward declaration. -class QWidget; -class QTableWidget; -class QToolBar; -class QMainWindow; - -/** Handles saving and restoring RShares's settings, such as the - * location of Tor, the control port, etc. - * - * NOTE: Qt 4.1 documentation states that constructing a QSettings object is - * "very fast", so we shouldn't need to create a global instance of this - * class. - */ -class RshareSettings : public QSettings -{ - -public: - /** Default constructor. */ - RshareSettings(); - - /** Resets all of Rshare's settings. */ - static void reset(); - - /** Sets the default value of key to be val. */ - void setDefault(QString key, QVariant val); - /** Returns the default value for key. */ - QVariant defaultValue(QString key); - /** Save val to the configuration file for the setting key, if - * val is different than key's current value. */ - void setValue(QString key, QVariant val); - /** Returns the value for key. If no value is currently saved, then - * the default value for key will be returned. */ - QVariant value(QString key); - /** Returns the value for key. If no value is currently saved, then - * defaultValue will be returned. */ - QVariant value(QString key, QVariant defaultValue); - - /** Gets the currently preferred language code for RShare. */ - QString getLanguageCode(); - /** Saves the preferred language code. */ - void setLanguageCode(QString languageCode); - - /** Gets the interface style key (e.g., "windows", "motif", etc.) */ - QString getInterfaceStyle(); - /** Sets the interface style key. */ - void setInterfaceStyle(QString styleKey); - - /** Sets the stylesheet */ - void setSheetName(QString sheet); - /** Gets the stylesheet */ - QString getSheetName(); - - /** Returns true if RetroShare's main window should be visible when the - * application starts. */ - bool showMainWindowAtStart(); - /** Sets whether to show Vidalia's main window when the application starts. */ - void setShowMainWindowAtStart(bool show); - - /** Returns true if RetroShare should start on system boot. */ - bool runRetroshareOnBoot(); - /** Set whether to run RetroShare on system boot. */ - void setRunRetroshareOnBoot(bool run); - - - /* Get the destination log file. */ - QString getLogFile(); - /** Set the destination log file. */ - void setLogFile(QString file); - - /* Get the bandwidth graph line filter. */ - uint getBWGraphFilter(); - /** Set the bandwidth graph line filter. */ - void setBWGraphFilter(uint line, bool status); - - /** Set the bandwidth graph opacity setting. */ - int getBWGraphOpacity(); - /** Set the bandwidth graph opacity settings. */ - void setBWGraphOpacity(int value); - - /** Gets whether the bandwidth graph is always on top. */ - bool getBWGraphAlwaysOnTop(); - /** Sets whether the bandwidth graph is always on top. */ - void setBWGraphAlwaysOnTop(bool alwaysOnTop); - - - //! Save placement, state and size information of a window. - void saveWidgetInformation(QWidget *widget); - - //! Load placement, state and size information of a window. - void loadWidgetInformation(QWidget *widget); - - //! Method overload. Save window and toolbar information. - void saveWidgetInformation(QMainWindow *widget, QToolBar *toolBar); - - //! Method overload. Restore window and toolbar information. - void loadWidgetInformation(QMainWindow *widget, QToolBar *toolBar); - - -private: - QHash _defaults; - - - -}; - -#endif - diff --git a/retroshare-gui/src/gui/LibraryDialog.cpp b/retroshare-gui/src/gui/LibraryDialog.cpp index 8eaedd4fb..d88c30c5c 100644 --- a/retroshare-gui/src/gui/LibraryDialog.cpp +++ b/retroshare-gui/src/gui/LibraryDialog.cpp @@ -31,6 +31,7 @@ #include "util/RsAction.h" #include "msgs/ChanMsgDialog.h" +#include "library/FindWindow.h" #include #include @@ -58,6 +59,8 @@ #define IMAGE_PROGRESS ":/images/browse-looking.gif" #define IMAGE_LIBRARY ":/images/library.png" +QString fileToFind; + /** Constructor */ LibraryDialog::LibraryDialog(QWidget *parent) @@ -73,7 +76,8 @@ LibraryDialog::LibraryDialog(QWidget *parent) ui.organizertreeView->setModel(dmodel); ui.organizerListView->setModel(dmodel); ui.organizerListView->setSpacing(10); - QDir DwnlFolder,ShrFolder; + QDir retroshareLib; + retroshareLib.mkdir("RetroShare Library"); connect(ui.shareFiles_btn,SIGNAL(clicked()),this, SLOT(CallShareFilesBtn_library())); @@ -98,10 +102,14 @@ LibraryDialog::LibraryDialog(QWidget *parent) void LibraryDialog::PopulateList() { + QDir dir; + QString libPath; + QDirModel *dirmodel=new QDirModel(this); - ui.organizertreeView->setModel(dirmodel); - QModelIndex cmodel=dirmodel->index(QDir::rootPath()); - ui.organizertreeView->setRootIndex(cmodel); + //ui.organizertreeView->setModel(dirmodel); + libPath=dir.currentPath(); + //QModelIndex cmodel=dirmodel->index(QDir::rootPath()); + //ui.organizertreeView->setRootIndex(cmodel); } @@ -131,4 +139,15 @@ void LibraryDialog::CallDeleteAlbumBtn_library() //QMessageBox::information(this, tr("RetroShare"),tr("Will be Introducing this .. soon- Delete Album in Library")); } +QString LibraryDialog::filePass() +{ + fileToFind=ui.findEditmain->text(); + return fileToFind; +} +void LibraryDialog::CallFindBtn_library() +{ + filePass(); + FindWindow *files = new FindWindow(this); + files->show(); +} diff --git a/retroshare-gui/src/gui/LibraryDialog.h b/retroshare-gui/src/gui/LibraryDialog.h index 04d378887..10ff72584 100644 --- a/retroshare-gui/src/gui/LibraryDialog.h +++ b/retroshare-gui/src/gui/LibraryDialog.h @@ -1,7 +1,7 @@ /**************************************************************** * RetroShare is distributed under the following license: * - * Copyright (C) 2008, crypton + * Copyright (C) 2008, defnax * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -41,7 +41,7 @@ public: LibraryDialog(QWidget *parent = 0); /** Default Destructor */ - + QString filePass(); private slots: @@ -53,6 +53,7 @@ private slots: void CallShowDetailsBtn_library(); void CallCreateAlbumBtn_library(); void CallDeleteAlbumBtn_library(); + void CallFindBtn_library(); diff --git a/retroshare-gui/src/gui/LibraryDialog.ui b/retroshare-gui/src/gui/LibraryDialog.ui index 87e021fa3..ca6d9bdde 100644 --- a/retroshare-gui/src/gui/LibraryDialog.ui +++ b/retroshare-gui/src/gui/LibraryDialog.ui @@ -672,5 +672,22 @@ - + + + organizertreeView + clicked(QModelIndex) + organizerListView + setCurrentIndex(QModelIndex) + + + 139 + 230 + + + 439 + 238 + + + + diff --git a/retroshare-gui/src/gui/ShareFilesDialog.ui b/retroshare-gui/src/gui/ShareFilesDialog.ui index d97325324..d48bbb33c 100644 --- a/retroshare-gui/src/gui/ShareFilesDialog.ui +++ b/retroshare-gui/src/gui/ShareFilesDialog.ui @@ -54,7 +54,7 @@ - + Cancel @@ -71,18 +71,18 @@ - pushButton_4 + cancel_pushButton clicked() - sharedFile_dialog + ShareFilesDialog reject() - 495 - 290 + 499 + 283 - 495 - 319 + 278 + 157 diff --git a/retroshare-gui/src/gui/library/FindWindow.cpp b/retroshare-gui/src/gui/library/FindWindow.cpp new file mode 100644 index 000000000..66fe8ace9 --- /dev/null +++ b/retroshare-gui/src/gui/library/FindWindow.cpp @@ -0,0 +1,201 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2008, defnax + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include +//#include "ui_FileWindow.h" +#include "findwindow.h" +#include "Gui/LibraryDialog.h" + +extern QString fileToFind; + + FindWindow::FindWindow(QWidget *parent) + : QDialog(parent) + { + browseButton = createButton(tr("&Browse..."), SLOT(browse())); + findButton = createButton(tr("&Find"), SLOT(find())); + + fileComboBox = createComboBox(fileToFind); + textComboBox = createComboBox(); + directoryComboBox = createComboBox(); + + fileLabel = new QLabel(tr("Named:")); + textLabel = new QLabel(tr("Containing text:")); + directoryLabel = new QLabel(tr("In directory:")); + filesFoundLabel = new QLabel; + + createFilesTable(); + + QHBoxLayout *buttonsLayout = new QHBoxLayout; + buttonsLayout->addStretch(); + buttonsLayout->addWidget(findButton); + + QGridLayout *mainLayout = new QGridLayout; + mainLayout->addWidget(fileLabel, 0, 0); + mainLayout->addWidget(fileComboBox, 0, 1, 1, 2); + mainLayout->addWidget(textLabel, 1, 0); + mainLayout->addWidget(textComboBox, 1, 1, 1, 2); + mainLayout->addWidget(directoryLabel, 2, 0); + mainLayout->addWidget(directoryComboBox, 2, 1); + mainLayout->addWidget(browseButton, 2, 2); + mainLayout->addWidget(filesTable, 3, 0, 1, 3); + mainLayout->addWidget(filesFoundLabel, 4, 0); + mainLayout->addLayout(buttonsLayout, 5, 0, 1, 3); + setLayout(mainLayout); + + setWindowTitle(tr("Find Files")); + resize(700, 300); + } + + void FindWindow::browse() + { + QString directory = QFileDialog::getExistingDirectory(this, + tr("Find Files"), QDir::currentPath()); + if (!directory.isEmpty()) { + directoryComboBox->addItem(directory); + directoryComboBox->setCurrentIndex(directoryComboBox->currentIndex() + 1); + } + } + + void FindWindow::find() + { + filesTable->setRowCount(0); + + QString fileName = fileComboBox->currentText(); + QString text = textComboBox->currentText(); + QString path = directoryComboBox->currentText(); + + + QDir directory = QDir(path); + QStringList files,folders; + + if (fileName.isEmpty()) + fileName = "*"; + files = directory.entryList(QStringList(fileName), + QDir::Files |QDir::NoSymLinks); + folders=directory.entryList(QStringList(fileName), + QDir::Dirs | QDir::NoSymLinks); + //QMessageBox::information(this,"path",path); + + files = findFiles(directory, files, text); + if(text.isEmpty()){ + showFolders(directory, folders); + showFiles(directory, files); + } + else if(!text.isEmpty()){ + showFiles(directory, files); + } + QLocale d; + if (files.isEmpty()) + { + if(d.toString(folders.size())!=0){ + for(int i=folders.size();i>0;i--) + directory.cd(folders[i]); + //QMessageBox::information(this,"dir",directory.dirName()); + } + } + } +QStringList FindWindow::findFiles( QDir &directory, QStringList &files, + QString &text) + { + QStringList foundFiles; + + for (int i = 0; i < files.size(); ++i) { + QFile file(directory.absoluteFilePath(files[i])); + + if (file.open(QIODevice::ReadOnly)) { + QString line; + QTextStream in(&file); + while (!in.atEnd()) { + line = in.readLine(); + if (line.contains(text)) { + foundFiles << files[i]; + break; + } + } + } + } + return foundFiles; + } + + void FindWindow::showFiles(const QDir &directory, const QStringList &files) + { + for (int i = 0; i < files.size(); ++i) { + QFile file(directory.absoluteFilePath(files[i])); + qint64 size = QFileInfo(file).size(); + + QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]); + fileNameItem->setFlags(Qt::ItemIsEnabled); + QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB") + .arg(int((size + 1023) / 1024))); + sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + sizeItem->setFlags(Qt::ItemIsEnabled); + + int row = filesTable->rowCount(); + filesTable->insertRow(row); + filesTable->setItem(row, 0, fileNameItem); + filesTable->setItem(row, 1, sizeItem); + } + filesFoundLabel->setText(tr("%1 file(s) found").arg(files.size())); + } + +void FindWindow::showFolders(const QDir &directory, const QStringList &folders) + { + for (int i = 0; i < folders.size(); ++i) { + QDir folder(directory.absoluteFilePath(folders[i])); + + QTableWidgetItem *fileNameItem = new QTableWidgetItem(folders[i]); + fileNameItem->setFlags(Qt::ItemIsEnabled); + + + int row = filesTable->rowCount(); + filesTable->insertRow(row); + filesTable->setItem(row, 0, fileNameItem); + + } + return ; + } + + QPushButton *FindWindow::createButton(const QString &text, const char *member) + { + QPushButton *button = new QPushButton(text); + connect(button, SIGNAL(clicked()), this, member); + return button; + } + + QComboBox *FindWindow::createComboBox(const QString &text) + { + QComboBox *comboBox = new QComboBox; + comboBox->setEditable(true); + comboBox->addItem(text); + comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + return comboBox; + } + + void FindWindow::createFilesTable() + { + filesTable = new QTableWidget(0, 2); + QStringList labels; + labels << tr("File Name") << tr("Size"); + filesTable->setHorizontalHeaderLabels(labels); + filesTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); + filesTable->verticalHeader()->hide(); + filesTable->setShowGrid(false); + } diff --git a/retroshare-gui/src/gui/library/FindWindow.h b/retroshare-gui/src/gui/library/FindWindow.h new file mode 100644 index 000000000..3ffd6a291 --- /dev/null +++ b/retroshare-gui/src/gui/library/FindWindow.h @@ -0,0 +1,64 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2008, defnax + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + + #ifndef FINDWINDOW_H + #define FINDWINDOW_H + + #include + + class QComboBox; + class QDir; + class QLabel; + class QPushButton; + class QTableWidget; + + class FindWindow : public QDialog + { + Q_OBJECT + + public: + FindWindow(QWidget *parent = 0); + + private slots: + void browse(); + void find(); + + private: + QStringList findFiles( QDir &directory, QStringList &files, + QString &text); + void showFiles(const QDir &directory, const QStringList &files); + void showFolders(const QDir &directory, const QStringList &folders); + QPushButton *createButton(const QString &text, const char *member); + QComboBox *createComboBox(const QString &text = QString()); + void createFilesTable(); + + QComboBox *fileComboBox; + QComboBox *textComboBox; + QComboBox *directoryComboBox; + QLabel *fileLabel; + QLabel *textLabel; + QLabel *directoryLabel; + QLabel *filesFoundLabel; + QPushButton *browseButton; + QPushButton *findButton; + QTableWidget *filesTable; + }; +#endif