Пример #1
0
QString Paths::resourceDir(const QString& file)
{
  auto resourceDir = QDir(QGuiApplication::applicationDirPath());

#ifdef Q_OS_MAC
  resourceDir.cdUp();
  resourceDir.cd("Resources");
#endif

  return resourceDir.filePath(file);
}
Пример #2
0
FileSystemWidget::FileSystemWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FileSystemWidget)
{
    ui->setupUi(this);

    m_delegate = new FileSystemItemDelegate(this);
    ui->listView->setItemDelegate(m_delegate);

    initModel();
    ui->listView->setModel(m_sortModel);
    connect(ui->listView, SIGNAL(open(QModelIndex)),m_model, SLOT(cd(QModelIndex)));
    connect(ui->listView, SIGNAL(up()),             m_model, SLOT(cdUp()));
    connect(ui->listView, SIGNAL(play(QStringList,bool,bool)), this, SLOT(play(QStringList,bool,bool)));

    initSearch();

    ui->progressPanel->hide();

    connect(ui->upButton,       SIGNAL(clicked()),      m_model,        SLOT(cdUp()));
    connect(m_model,            SIGNAL(upChanged(bool)),ui->upButton,   SLOT(setEnabled(bool)));
    connect(m_model,            SIGNAL(pathChanged()),  this,           SLOT(onPathChanged()));
    connect(ui->selectButton,   SIGNAL(clicked()),      this,           SLOT(selectFolder()));

    connect(ui->playAllButton,  SIGNAL(clicked()), this,    SLOT(playAll()));
    connect(ui->playRootButton, SIGNAL(clicked()), this,    SLOT(playRoot()));

    connect(ui->addAllButton,   SIGNAL(clicked()), this,    SLOT(addAll()));
    connect(ui->addRootButton,  SIGNAL(clicked()), this,    SLOT(addRoot()));

    m_scanDialog = new ScanProgressDialog(this);
    connect(m_scanDialog,                   SIGNAL(cancelled()),                Player::instance()->folder(), SLOT(cancel()));
    connect(Player::instance()->folder(),   SIGNAL(cancelled()),                m_scanDialog,       SLOT(onScanCancelled()));
    connect(Player::instance()->folder(),   SIGNAL(scanPathChanged(QString)),   m_scanDialog,       SLOT(setScanPath(QString)));
    connect(Player::instance()->folder(),   SIGNAL(finished(int)),              m_scanDialog,       SLOT(onScanFinished(int)));

    m_scanDialogTimer.setSingleShot(true);
    connect(&m_scanDialogTimer,             SIGNAL(timeout()),                  this,               SLOT(showScanDialog()));
    connect(Player::instance()->folder(),   SIGNAL(finished(int)),              &m_scanDialogTimer, SLOT(stop()));
}
Пример #3
0
void QxFileSystemView::keyPressEvent(QKeyEvent* event)
{
	bool ctrl = (event->modifiers() & Qt::ControlModifier) != 0;
	int key = event->key();
	if (key == Qt::Key_Delete)
		emit delKeyPressed();
	else if (key == Qt::Key_Space)
		emit activated(currentIndex());
	else if (key == Qt::Key_Escape)
		emit escape();
	else if (ctrl & (key == Qt::Key_Up))
		emit cdUp();
	else
		QTreeView::keyPressEvent(event);
}
Пример #4
0
void DiskBrowserView::keyPressEvent(QKeyEvent *event) {
  //enhance consistency: OS X by default doesn't activate items for these keypresses
  if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
    emit activated(currentIndex());
    return;
  }

  //simulate popular file managers; backspace = go up one directory
  if(event->key() == Qt::Key_Backspace) {
    emit cdUp();
    return;
  }

  //fallback: unrecognized keypresses get handled by the widget itself
  QTreeView::keyPressEvent(event);
}
Пример #5
0
void TableView::keyPressEvent(QKeyEvent *event)
{
    if(event == NULL)
        return;

    switch(event->key())
    {
    case Qt::Key_Return:
        openItem(currentIndex());
        break;

    case Qt::Key_Backspace:
        cdUp();
        break;

    default:
        QTableView::keyPressEvent(event);
        break;
    }

    event->ignore();
}
Пример #6
0
void DensityViewerWindow::openFile() {
    auto filename = QFileDialog::getOpenFileName(this,
         "Open dataset", QDir::currentPath() , "Yell files (*.h5)");

    if(filename=="")
        return;

    try {
        densityViewer->loadDensityData(filename);
    } catch (UnknownFormat) {
      auto error = new QErrorMessage(this);
      error->showMessage("File cannot be opened because it is in unknown format.");
      return;
    }

    currentFile = filename;
    auto p = QDir(filename);
    p.cdUp();

    QDir::setCurrent(p.path());
    updateProgramTitle();
}
Пример #7
0
FileBrowser::FileBrowser(LiteApi::IApplication *app, QObject *parent) :
    QObject(parent),
    m_liteApp(app)
{
    m_widget = new QWidget;
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);

    QDir::Filters filters = QDir::AllDirs | QDir::Files | QDir::Drives
                            | QDir::Readable| QDir::Writable
                            | QDir::Executable /*| QDir::Hidden*/
                            | QDir::NoDotAndDotDot;

    bool bShowHiddenFiles = m_liteApp->settings()->value(FILEBROWSER_SHOW_HIDDEN_FILES,false).toBool();
    if (bShowHiddenFiles) {
        filters |= QDir::Hidden;
    }

#ifdef Q_OS_WIN // Symlinked directories can cause file watcher warnings on Win32.
    filters |= QDir::NoSymLinks;
#endif
    //create filter toolbar
    //m_filterToolBar = new QToolBar(m_widget);
    //m_filterToolBar->setIconSize(QSize(16,16));

    m_syncAct = new QAction(QIcon("icon:images/sync.png"),tr("Synchronize with editor"),this);
    m_syncAct->setCheckable(true);

    m_reloadAct = new QAction(QIcon("icon:filebrowser/images/reload.png"),tr("Reload Folder"),this);

    m_showHideFilesAct = new QAction(tr("Show Hidden Files"),this);
    m_showHideFilesAct->setCheckable(true);
    if (bShowHiddenFiles) {
        m_showHideFilesAct->setChecked(true);
    }
    connect(m_showHideFilesAct,SIGNAL(triggered(bool)),this,SLOT(showHideFiles(bool)));

    m_executeFileAct = new QAction(tr("Execute File"),this);
    connect(m_executeFileAct,SIGNAL(triggered()),this,SLOT(executeFile()));

//    m_filterCombo = new QComboBox;
//    m_filterCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
//    m_filterCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
//    m_filterCombo->setEditable(true);
//    m_filterCombo->addItem("*");
//    m_filterCombo->addItem("Makefile;*.go;*.cgo;*.s;*.goc;*.y;*.e64;*.pro");
//    m_filterCombo->addItem("*.sh;Makefile;*.go;*.cgo;*.s;*.goc;*.y;*.*.c;*.cpp;*.h;*.hpp;*.e64;*.pro");

    //m_filterToolBar->addAction(m_syncAct);
    //m_filterToolBar->addSeparator();
    //m_filterToolBar->addWidget(m_filterCombo);

    //create root toolbar
    m_rootToolBar = new QToolBar(m_widget);
    m_rootToolBar->setIconSize(QSize(16,16));

    m_cdupAct = new QAction(QIcon("icon:filebrowser/images/cdup.png"),tr("Open Parent"),this);

    m_rootCombo = new QComboBox;
    m_rootCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    m_rootCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
    m_rootCombo->setEditable(false);

    m_rootToolBar->addAction(m_cdupAct);
    m_rootToolBar->addAction(m_reloadAct);
    m_rootToolBar->addSeparator();
    m_rootToolBar->addWidget(m_rootCombo);

#ifdef Q_OS_MAC
    m_folderView = new FolderView(true,m_liteApp);
#else
    m_folderView = new FolderView(false,m_liteApp);
#endif
    m_folderView->setRootIsDecorated(true);
    m_folderView->setFilter(filters);
    //mainLayout->addWidget(m_filterToolBar);
    mainLayout->addWidget(m_rootToolBar);
    mainLayout->addWidget(m_folderView);

    m_widget->setLayout(mainLayout);

    m_setRootAct = new QAction(tr("Set As Root Folder"),this);
    m_openFolderInNewWindowAct = new QAction(tr("Open Folder in New Window"),this);
    m_addToFoldersAct = new QAction(tr("Add to Folders"),this);

    connect(m_setRootAct,SIGNAL(triggered()),this,SLOT(setFolderToRoot()));
    connect(m_cdupAct,SIGNAL(triggered()),this,SLOT(cdUp()));
    connect(m_openFolderInNewWindowAct,SIGNAL(triggered()),this,SLOT(openFolderInNewWindow()));
    connect(m_addToFoldersAct,SIGNAL(triggered()),this,SLOT(addToFolders()));

    QList<QAction*> actions;
    m_filterMenu = new QMenu(tr("Filter"));
    m_filterMenu->setIcon(QIcon("icon:images/filter.png"));
    m_filterMenu->addAction(m_showHideFilesAct);
    actions << m_filterMenu->menuAction() << m_syncAct;

    m_toolWindowAct = m_liteApp->toolWindowManager()->addToolWindow(Qt::LeftDockWidgetArea,m_widget,"filesystem",tr("File System"),true,actions);
    connect(m_toolWindowAct,SIGNAL(toggled(bool)),this,SLOT(visibilityChanged(bool)));
    //connect(m_filterCombo,SIGNAL(activated(QString)),this,SLOT(activatedFilter(QString)));
    connect(m_rootCombo,SIGNAL(activated(QString)),this,SLOT(activatedRoot(QString)));
    connect(m_syncAct,SIGNAL(triggered(bool)),this,SLOT(syncFileModel(bool)));
    connect(m_reloadAct,SIGNAL(triggered()),this,SLOT(reloadFileModel()));
    connect(m_liteApp->editorManager(),SIGNAL(currentEditorChanged(LiteApi::IEditor*)),this,SLOT(currentEditorChanged(LiteApi::IEditor*)));
    connect(m_folderView,SIGNAL(aboutToShowContextMenu(QMenu*,LiteApi::FILESYSTEM_CONTEXT_FLAG,QFileInfo)),this,SLOT(aboutToShowContextMenu(QMenu*,LiteApi::FILESYSTEM_CONTEXT_FLAG,QFileInfo)));
    //connect(m_folderView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openEditor(QModelIndex)));
    connect(m_folderView,SIGNAL(activated(QModelIndex)),this,SLOT(activatedFolderView(QModelIndex)));

    QString root = m_liteApp->settings()->value("FileBrowser/root","").toString();
    if (!root.isEmpty()) {
        addFolderToRoot(root);
    }
    bool b = m_liteApp->settings()->value("FileBrowser/synceditor",true).toBool();
    if (b) {
        m_syncAct->setChecked(true);
    }
}
Пример #8
0
FileBrowser::FileBrowser(LiteApi::IApplication *app, QObject *parent) :
    QObject(parent),
    m_liteApp(app)
{
    m_widget = new QWidget;
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);

    m_fileModel = new QFileSystemModel(this);
    m_fileModel->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);

    m_proxyModel = new QSortFileSystemProxyModel(this);
    m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
    m_proxyModel->setDynamicSortFilter(true);
    m_proxyModel->setSourceModel(m_fileModel);
    m_proxyModel->sort(0);

    //create filter toolbar
    m_filterToolBar = new QToolBar(m_widget);
    m_filterToolBar->setIconSize(QSize(16,16));

    m_syncAct = new QAction(QIcon("icon:filebrowser/images/sync.png"),tr("Synchronize with editor"),this);
    m_syncAct->setCheckable(true);

    m_filterCombo = new QComboBox;
    m_filterCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    m_filterCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
    m_filterCombo->setEditable(true);
    m_filterCombo->addItem("*");
    m_filterCombo->addItem("Makefile;*.go;*.cgo;*.s;*.goc;*.y;*.e64;*.pro");
    m_filterCombo->addItem("*.sh;Makefile;*.go;*.cgo;*.s;*.goc;*.y;*.*.c;*.cpp;*.h;*.hpp;*.e64;*.pro");

    m_filterToolBar->addAction(m_syncAct);
    m_filterToolBar->addSeparator();
    m_filterToolBar->addWidget(m_filterCombo);

    //create root toolbar
    m_rootToolBar = new QToolBar(m_widget);
    m_rootToolBar->setIconSize(QSize(16,16));

    m_cdupAct = new QAction(QIcon("icon:filebrowser/images/cdup.png"),tr("Open Parent"),this);

    m_rootCombo = new QComboBox;
    m_rootCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    m_rootCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
    m_rootCombo->setEditable(false);
    m_rootCombo->addItem(m_fileModel->myComputer().toString());

    m_rootToolBar->addAction(m_cdupAct);
    m_rootToolBar->addSeparator();
    m_rootToolBar->addWidget(m_rootCombo);

    //create treeview
    m_treeView = new QTreeView;
    m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
    m_treeView->setModel(m_proxyModel);

    m_treeView->setRootIsDecorated(true);
    m_treeView->setUniformRowHeights(true);
    m_treeView->setTextElideMode(Qt::ElideNone);
    m_treeView->setAttribute(Qt::WA_MacShowFocusRect, false);

    m_treeView->setHeaderHidden(true);
    m_treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // show horizontal scrollbar
#if QT_VERSION >= 0x050000
    m_treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
    m_treeView->header()->setResizeMode(QHeaderView::ResizeToContents);
#endif
    m_treeView->header()->setStretchLastSection(false);
    //hide
    int count = m_treeView->header()->count();
    for (int i = 1; i < count; i++) {
        m_treeView->setColumnHidden(i,true);
    }

    mainLayout->addWidget(m_filterToolBar);
    mainLayout->addWidget(m_rootToolBar);
    mainLayout->addWidget(m_treeView);
    m_widget->setLayout(mainLayout);

    //create menu
    m_fileMenu = new QMenu;
    m_folderMenu = new QMenu;
    m_rootMenu = new QMenu;

    m_openFileAct = new QAction(tr("Open File"),this);
    //m_openEditorAct = new QAction(tr("Open Editor"),this);
    m_newFileAct = new QAction(tr("New File..."),this);
    m_newFileWizardAct = new QAction(tr("New File Wizard..."),this);
    m_renameFileAct = new QAction(tr("Rename File..."),this);
    m_removeFileAct = new QAction(tr("Delete File"),this);

    m_setRootAct = new QAction(tr("Set As Root Folder"),this);
    m_newFolderAct = new QAction(tr("New Folder..."),this);
    m_renameFolderAct = new QAction(tr("Rename Folder..."),this);
    m_removeFolderAct = new QAction(tr("Delete Folder"),this);

    m_openShellAct = new QAction(tr("Open Terminal Here"),this);
    m_openExplorerAct = new QAction(tr("Open Explorer Here"),this);

    m_viewGodocAct = new QAction(tr("View Godoc Here"),this);

    m_loadFolderAct = new QAction(tr("Load Folder Project"),this);

    m_fileMenu->addAction(m_openFileAct);
    //m_fileMenu->addAction(m_openEditorAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_newFileAct);
    m_fileMenu->addAction(m_newFileWizardAct);
    m_fileMenu->addAction(m_renameFileAct);
    m_fileMenu->addAction(m_removeFileAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_loadFolderAct);
    m_fileMenu->addAction(m_viewGodocAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_openShellAct);
    m_fileMenu->addAction(m_openExplorerAct);

    m_folderMenu->addAction(m_setRootAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_newFileAct);
    m_folderMenu->addAction(m_newFileWizardAct);
    m_folderMenu->addAction(m_newFolderAct);
    m_folderMenu->addAction(m_renameFolderAct);
    m_folderMenu->addAction(m_removeFolderAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_loadFolderAct);
    m_folderMenu->addAction(m_viewGodocAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_openShellAct);
    m_folderMenu->addAction(m_openExplorerAct);

    m_rootMenu->addAction(m_cdupAct);
    m_rootMenu->addSeparator();
    m_rootMenu->addAction(m_newFileAct);
    m_rootMenu->addAction(m_newFileWizardAct);
    m_rootMenu->addAction(m_newFolderAct);
    m_rootMenu->addSeparator();
    m_rootMenu->addAction(m_loadFolderAct);
    m_rootMenu->addSeparator();
    m_rootMenu->addAction(m_openShellAct);
    m_rootMenu->addAction(m_openExplorerAct);

    connect(m_openFileAct,SIGNAL(triggered()),this,SLOT(openFile()));
    //connect(m_openEditorAct,SIGNAL(triggered()),this,SLOT(openEditor()));    
    connect(m_newFileAct,SIGNAL(triggered()),this,SLOT(newFile()));
    connect(m_newFileWizardAct,SIGNAL(triggered()),this,SLOT(newFileWizard()));
    connect(m_renameFileAct,SIGNAL(triggered()),this,SLOT(renameFile()));
    connect(m_removeFileAct,SIGNAL(triggered()),this,SLOT(removeFile()));
    connect(m_newFolderAct,SIGNAL(triggered()),this,SLOT(newFolder()));
    connect(m_renameFolderAct,SIGNAL(triggered()),this,SLOT(renameFolder()));
    connect(m_removeFolderAct,SIGNAL(triggered()),this,SLOT(removeFolder()));
    connect(m_openShellAct,SIGNAL(triggered()),this,SLOT(openShell()));
    connect(m_setRootAct,SIGNAL(triggered()),this,SLOT(setFolderToRoot()));
    connect(m_cdupAct,SIGNAL(triggered()),this,SLOT(cdUp()));
    connect(m_openExplorerAct,SIGNAL(triggered()),this,SLOT(openExplorer()));
    connect(m_viewGodocAct,SIGNAL(triggered()),this,SLOT(viewGodoc()));
    connect(m_loadFolderAct,SIGNAL(triggered()),this,SLOT(loadFolderProject()));

    //QDockWidget *dock = m_liteApp->dockManager()->addDock(m_widget,tr("File Browser"));
    //connect(dock,SIGNAL(visibilityChanged(bool)),this,SLOT(visibilityChanged(bool)));
    m_toolWindowAct = m_liteApp->toolWindowManager()->addToolWindow(Qt::LeftDockWidgetArea,m_widget,"filesystem",tr("File System"),true);
    connect(m_toolWindowAct,SIGNAL(toggled(bool)),this,SLOT(visibilityChanged(bool)));
    connect(m_treeView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClickedTreeView(QModelIndex)));
    connect(m_filterCombo,SIGNAL(activated(QString)),this,SLOT(activatedFilter(QString)));
    connect(m_rootCombo,SIGNAL(activated(QString)),this,SLOT(activatedRoot(QString)));
    connect(m_syncAct,SIGNAL(triggered(bool)),this,SLOT(syncFileModel(bool)));
    connect(m_liteApp->editorManager(),SIGNAL(currentEditorChanged(LiteApi::IEditor*)),this,SLOT(currentEditorChanged(LiteApi::IEditor*)));
    connect(m_treeView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(treeViewContextMenuRequested(QPoint)));

    QString root = m_liteApp->settings()->value("FileBrowser/root",m_fileModel->myComputer().toString()).toString();
    addFolderToRoot(root);
    bool b = m_liteApp->settings()->value("FileBrowser/synceditor",true).toBool();
    if (b) {
        m_syncAct->setChecked(true);
    }
}
Пример #9
0
QxFileBrowser::QxFileBrowser(QWidget* parent)
	: QWidget(parent),
	  gotoMenu_(0),
	  recentMenu_(0),
	  showHidden_(false),
	  showDetails_(true),
	  createFileDialog_(0),
	  createDirDialog_(0),
	  renameDialog_(0)
{
	//--------------------------------------------------------------------------
	// setup primary model and view
	
	cwdModel_ = new QFileSystemModel(this);
	cwdModel_->setReadOnly(false);
	QModelIndex root = cwdModel_->setRootPath(QDir::currentPath());
	connect( cwdModel_, SIGNAL(fileRenamed(const QString&, const QString&, const QString&)),
	         this, SLOT(fileRenamed(const QString&, const QString&, const QString&)) );
	
	dirView_ = new QxFileSystemView(this);
	dirView_->setModel(cwdModel_);
	dirView_->header()->hide();
	dirView_->setRootIndex(root);
	dirView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	dirView_->setDragDropMode(QAbstractItemView::DragOnly);
	connect(dirView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(cwdSet(const QModelIndex&)));
	connect(dirView_, SIGNAL(escape()), this, SIGNAL(escape()));
	connect(dirView_, SIGNAL(cdUp()), this, SLOT(cdUp()));
	connect(cwdModel_, SIGNAL(layoutChanged()), dirView_, SLOT(resizeColumnsToContents()));
	
	setFocusProxy(dirView_);
	
	// dirView_->setTextElideMode(Qt::ElideMiddle);
	dirView_->setFrameStyle(QFrame::NoFrame);
	// dirView_->setIndentation(18); // together with a branch pixmap could improve branch alignment
	dirView_->setLineWidth(0);
	dirView_->setMidLineWidth(0);
	#ifdef Q_WS_MAC
	dirView_->setStyleSheet(
		"QTreeView {"
		"  font-size: 12px;"
		"}"
		"QTreeView::item {"
		"  padding-top: 1px;"
		"}"
	);
	#endif
	{
		QPalette pal = dirView_->palette();
		pal.setColor(QPalette::Base, styleManager()->color("fileBrowserDirViewBgColor"));
		dirView_->setPalette(pal);
	}
	
	//--------------------------------------------------------------------------
	// setup navigation bar / panel head
	
	gotoButton_ = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserGotoButton")));
	gotoButton_->setMode(QxControl::MenuMode);
	gotoButton_->visual()->setText(QDir::current().dirName());
	gotoButton_->setMinimumWidth(10); // design HACK
	gotoButton_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
	{
		QPixmap folderIcon = QFileIconProvider().icon(QFileInfo(QDir::currentPath())).pixmap(QSize(16, 16));
		gotoButton_->visual()->setLeadingIcon(folderIcon);
	}
	#ifdef Q_WS_MAC
	#ifdef QT_MAC_USE_COCOA
	connect(gotoButton_, SIGNAL(toggled(bool)), this, SLOT(blockFloating(bool)));
	#endif // QT_MAC_USE_COCOA
	#endif // Q_WS_MAC
	
	updateGotoMenu();
	
	class QxCdUpButton: public QxControl {
	public:
		QxCdUpButton(QWidget* parent)
			: QxControl(parent, new QxVisual(styleManager()->style("fileBrowserCdUpButton")))
		{}
	private:
		// workaround HACK, prevent undocking, map double click event to single click
		virtual void mouseDoubleClickEvent(QMouseEvent* event) { press(); event->accept(); }
	};
	QxControl* cdUpButton = new QxCdUpButton(this);
	cdUpButton->setMode(QxControl::TouchMode);
	connect(cdUpButton, SIGNAL(pressed()), this, SLOT(cdUp()));
	
	//--------------------------------------------------------------------------
	// define context actions
	
	contextMenu_ = new QMenu(this);
	
	// QxDesignHack::beautify(contextMenu_);
	openDefaultAction_ = new QAction(tr("Open in Default App."), this);
	openDefaultAction_->setShortcut(tr("Ctrl+D"));
	openDefaultAction_->setShortcutContext(Qt::WidgetShortcut);
	openFileAction_ = new QAction(tr("Open in %1").arg(qApp->applicationName()), this);
	
	createFileAction_ = contextMenu_->addAction(tr("New File"));
	createDirAction_ = contextMenu_->addAction(tr("New Folder"));
	contextMenu_->addSeparator();
	contextMenu_->addAction(openFileAction_);
	contextMenu_->addAction(openDefaultAction_);
	contextMenu_->addSeparator();
	renameAction_ = contextMenu_->addAction(tr("Rename"));
	deleteAction_ = contextMenu_->addAction(tr("Move To Trash"));
	contextMenu_->addSeparator();
	bookmarkAction_ = contextMenu_->addAction(tr("Bookmark"));
	contextMenu_->addSeparator();
	showHiddenAction_ = contextMenu_->addAction(tr("Show Hidden"));
	showDetailsAction_ = contextMenu_->addAction(tr("Show Details"));
	
	connect(createFileAction_, SIGNAL(triggered()), this, SLOT(createFile()));
	connect(createDirAction_, SIGNAL(triggered()), this, SLOT(createDir()));
	connect(openDefaultAction_, SIGNAL(triggered()), this, SLOT(openDefault()));
	connect(openFileAction_, SIGNAL(triggered()), this, SLOT(openFile()));
	connect(renameAction_, SIGNAL(triggered()), this, SLOT(rename()));
	connect(deleteAction_, SIGNAL(triggered()), this, SLOT(delete_()));
	connect(dirView_, SIGNAL(delKeyPressed()), this, SLOT(delete_()));
	connect(showHiddenAction_, SIGNAL(toggled(bool)), this, SLOT(showHidden(bool)));
	connect(showDetailsAction_, SIGNAL(toggled(bool)), this, SLOT(showDetails(bool)));
	connect(bookmarkAction_, SIGNAL(triggered()), this, SLOT(bookmark()));
	
	showHiddenAction_->setCheckable(true);
	showDetailsAction_->setCheckable(true);
	showHiddenAction_->setChecked(false);
	showDetailsAction_->setChecked(false);
	
	//--------------------------------------------------------------------------
	// setup toolbar
	
	QxControl* plusButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserPlusButton")));
	plusButton->setMode(QxControl::TouchMode);
	connect(plusButton, SIGNAL(pressed()), this, SLOT(createFile()));
	
	QxControl* wheelButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserWheelButton")));
	wheelButton->setMenu(contextMenu_);
	wheelButton->setMenuPopupMode(QxControl::DownsideMenuPopup|QxControl::UpsideMenuPopup|QxControl::PreferUpsideMenuPopup);
	
	QxControl* recentButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserRecentButton")));
	recentButton->setMode(QxControl::TouchMode);
	connect(recentButton, SIGNAL(pressed()), this, SLOT(recentShowOrHide()));
	
	QxControl* bookmarksButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserBookmarksButton")));
	bookmarksButton->setMode(QxControl::TouchMode);
	connect(bookmarksButton, SIGNAL(pressed()), this, SLOT(bookmarksShowOrHide()));
	
	statusBar_ = new QxStatusBar(this);
	
	showHidden(false);
	showDetails(false);
	
	//--------------------------------------------------------------------------
	// setup bottom views
	
	recentModel_ = new QxUrlListModel(this);
	
	recentView_ = new QxUrlListView(this);
	// recentView_->header()->hide();
	// recentView_->setViewMode(QListView::IconMode);
	// recentView_->setIconSize(QSize(16, 16));
	recentView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	recentView_->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
	recentView_->setTextElideMode(Qt::ElideLeft);
	recentView_->setFrameStyle(QFrame::NoFrame);
	recentView_->setLineWidth(0);
	recentView_->setMidLineWidth(0);
	recentView_->setStyleSheet(
		"QListView::item {"
		"  padding-top: 1px;"
		"}"
	);
	// recentView_->setAlternatingRowColors(true);
	recentView_->setModel(recentModel_);
	connect(recentView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(gotoRecent(const QModelIndex&)));
	
	recentContextMenu_ = new QMenu(this);
	recentContextMenu_->addAction(tr("Goto"), this, SLOT(gotoRecent()));
	recentContextMenu_->addAction(tr("Add To Bookmarks"), this, SLOT(recentAddToBookmarks()));
	
	bookmarksModel_ = new QxUrlListModel(this);
	bookmarksModel_->setPathReduction(1);
	
	bookmarksView_ = new QxUrlListView(this);
	bookmarksView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	bookmarksView_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	bookmarksView_->setTextElideMode(Qt::ElideLeft);
	bookmarksView_->setFrameStyle(QFrame::NoFrame);
	bookmarksView_->setLineWidth(0);
	bookmarksView_->setMidLineWidth(0);
	bookmarksView_->setStyleSheet(
		"QListView::item {"
		"  padding-top: 1px;"
		"}"
	);
	bookmarksView_->setModel(bookmarksModel_);
	bookmarksView_->setDragDropMode(QAbstractItemView::InternalMove);
	bookmarksView_->setDragEnabled(true);
	bookmarksView_->setAcceptDrops(true);
	bookmarksView_->setDropIndicatorShown(true);
	connect(bookmarksView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(gotoBookmark(const QModelIndex&)));
	
	bookmarksContextMenu_ = new QMenu(this);
	bookmarksContextMenu_->addAction(tr("Add Current Directory"), this, SLOT(cwdAddToBookmark()));
	bookmarksContextMenu_->addAction(tr("Add Other Directory"), this, SLOT(addDirBookmark()));
	bookmarksContextMenu_->addSeparator();
	bookmarksContextMenu_->addAction(tr("Goto Here"), this, SLOT(gotoBookmark()));
	bookmarksContextMenu_->addAction(tr("Remove From List"), this, SLOT(removeBookmark()));
	bookmarksContextMenu_->addSeparator();
	bookmarksShowFullPathAction_ = bookmarksContextMenu_->addAction(tr("Show Full Path"));
	bookmarksShowFullPathAction_->setCheckable(true);
	bookmarksShowFullPathAction_->setChecked(bookmarksModel_->pathReduction() == -1);
	connect(bookmarksShowFullPathAction_, SIGNAL(toggled(bool)), this, SLOT(bookmarksShowFullPath(bool)));
	
	#ifdef Q_WS_MAC
	{
		QProxyStyle* proxyStyle = qobject_cast<QProxyStyle*>(style());
		QMacStyle* macStyle = qobject_cast<QMacStyle*>((proxyStyle) ? proxyStyle->baseStyle() : style());
		if (macStyle) {
			macStyle->setFocusRectPolicy(dirView_, QMacStyle::FocusDisabled);
			macStyle->setFocusRectPolicy(recentView_, QMacStyle::FocusDisabled);
			macStyle->setFocusRectPolicy(dirView_, QMacStyle::FocusDisabled);
			macStyle->setFocusRectPolicy(bookmarksView_, QMacStyle::FocusDisabled);
		}
	}
	#endif
	
	//--------------------------------------------------------------------------
	// layout widgets
	
	handle_ = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserSplitter")));
	handle_->visual()->setText("");
	handleTextRecent_ = tr("Recent Places");
	handleTextBookmarks_ = tr("Bookmarks");
	
	bottomStack_ = new QxControl(this);
	bottomStackLayout_ = new QStackedLayout;
	bottomStackLayout_->addWidget(recentView_);
	bottomStackLayout_->addWidget(bookmarksView_);
	bottomStack_->setLayout(bottomStackLayout_);
	bottomStack_->setVisible(false);
	
	splitter_ = new QxSplitter(this);
	splitter_->setOrientation(Qt::Vertical);
	splitter_->setHandle(1, handle_);
	splitter_->setHandleWidth(styleManager()->constant("fileBrowserSplitterWidth"));
	splitter_->addWidget(dirView_);
	/*{
		QxControl* carrier = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserDirView")));
		QGridLayout* layout = new QGridLayout;
		layout->setSpacing(0);
		layout->setMargin(0);
		layout->addWidget(dirView_);
		carrier->setLayout(layout);
		splitter_->addWidget(carrier);
	}*/
	splitter_->addWidget(bottomStack_);
	
	// make dirView_ grow/shrink dynamically, while bottomStack_ keeps user-defined size
	splitter_->setStretchFactor(0, 1);
	splitter_->setStretchFactor(1, 0);
	
	QDockWidget* dock = qobject_cast<QDockWidget*>(parent);
	if (dock) {
		dock->setWidget(this);
		// connect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(adaptToDockLocation(Qt::DockWidgetArea)));
	}
	
	QVBoxLayout* col = new QVBoxLayout;
	col->setSpacing(0);
	col->setMargin(0);
	{
		QxControl* carrier = new QxControl(parent, new QxVisual(styleManager()->style("fileBrowserNavCarrier")));
		QHBoxLayout* row = new QHBoxLayout;
		row->setSpacing(0);
		row->setMargin(0);
		row->addWidget(gotoButton_);
		row->addStretch();
		row->addWidget(cdUpButton);
		carrier->setLayout(row);
		
		if (dock)
			dock->setTitleBarWidget(carrier);
		else
			col->addWidget(carrier);
	}
	col->addWidget(splitter_);
	col->addWidget(styleManager()->hl(this));
	{
		QBoxLayout* row = new QBoxLayout(QBoxLayout::LeftToRight);
		row->setSpacing(0);
		row->setMargin(0);
		row->addWidget(plusButton);
		row->addWidget(styleManager()->vl(this));
		row->addWidget(wheelButton);
		row->addWidget(styleManager()->vl(this));
		row->addWidget(recentButton);
		row->addWidget(styleManager()->vl(this));
		row->addWidget(bookmarksButton);
		row->addWidget(styleManager()->vl(this));
		row->addWidget(statusBar_);
		col->addLayout(row);
		
		bottomToolLayout_ = row;
	}
	setLayout(col);
}
Пример #10
0
bool UpdateSums(const plString& filename) {
    bool isUpdated = false;
    printf("%s:\n", filename.cstr());
    try {
        SumFile sum;
        plEncryptedStream S;
        plEncryptedStream::EncryptionType eType = plEncryptedStream::kEncXtea;
        if (!s_createFile) {
            if (!S.open(filename, fmRead, plEncryptedStream::kEncAuto)) {
                fprintf(stderr, "Could not open file %s\n", filename.cstr());
                return false;
            }
            eType = S.getEncType();
            sum.read(&S);
            S.close();
        }

        std::vector<SumEntry>::iterator it = sum.fEntries.begin();
        while (it != sum.fEntries.end()) {
            hsFileStream* IS = FindFilePath(it->fPath, cdUp(filename));
            if (IS == NULL) {
                if (s_autoYes) {
                    PrintFile(*it, '-');
                    it = sum.fEntries.erase(it);
                    isUpdated = true;
                } else {
                    fprintf(stderr, "File %s not found.  Remove it? [y/N] ",
                            it->fPath.cstr());
                    char buf[256];
                    fgets(buf, 256, stdin);

                    if (strcmp(buf, "y\n") == 0 || strcmp(buf, "Y\n") == 0) {
                        PrintFile(*it, '-');
                        it = sum.fEntries.erase(it);
                        isUpdated = true;
                    } else {
                        PrintFile(*it, '!');
                        ++it;
                    }
                }
                continue;
            }
            plMD5Hash hash = plMD5::hashStream(IS);
            it->fTimestamp = IS->getModTime();
            if (it->fHash != hash) {
                it->fHash = hash;
                PrintFile(*it, '*');
                isUpdated = true;
            } else {
                PrintFile(*it, ' ');
            }
            if (IS != NULL)
                delete IS;
            ++it;
        }

        if (isUpdated) {
            if (!S.open(filename, fmCreate, eType)) {
                fprintf(stderr, "Error: Could not open %s for writing!\n", filename.cstr());
                return false;
            }
            sum.write(&S);
            S.close();
        }
        printf("\n");
    } catch (hsException& e) {
        fprintf(stderr, "%s:%ld: %s\n", e.File(), e.Line(), e.what());
    } catch (...) {
        fprintf(stderr, "An unknown error occured\n");
    }
    return isUpdated;
}
Пример #11
0
void UTLauncher::startServerBrowser()
{
    splashTimer.singleShot(2000, this, SLOT(closeSplash()));

    if(!settings.value("StartMinimized", false).toBool()) {
        browser->show();
    } else {
        qApp->setQuitOnLastWindowClosed(false); // workaround for app not starting
    }
    browser->setMOTD(bootstrap.MOTD());
    
    auto hasEditorSupport = [=] {
        QString editorPath = bootstrap.editorExePath();
        QString projectPath = bootstrap.projectPath();
        return QFile::exists(editorPath) && QFile::exists(projectPath);
    };
    
    auto openSettings = [=](bool mandatoryEditor = false) {
        ConfigDialog dialog(settings, mandatoryEditor);
        dialog.exec();
        browser->setEditorSupport(hasEditorSupport());
        
        browser->setHideOnClose(settings.value("MinimizeToTrayOnClose").toBool());
    };
    
    connect(browser, &ServerBrowser::openServer, [=](QString url, bool spectate, bool inEditor) {

        if(inEditor) {
            QString editorPath = bootstrap.editorExePath();
            QString projectPath = bootstrap.projectPath();
            if(!editorPath.length() || !projectPath.length()) {
                openSettings(true);
                return;
            }
            QProcess::startDetached(editorPath, QStringList() << projectPath << "-GAME" << (url + (spectate?"?SpectatorOnly=1":"")) );
        } else {
            QString exePath = bootstrap.programExePath();
            if(!exePath.length()) {
                openSettings();
                return;
            }
            const auto serverEntry = browser->serverEntryFromAddress(url);
            auto launch = [=] {
                qDebug() << "Launching!!\n";
              QProcess::startDetached(exePath, QStringList()
#ifdef LAUNCH_WITH_UE4
                << "UnrealTournament"
#endif
                << (url + (spectate?"?SpectatorOnly=1":"")) 
                << "-SaveToUserDir");
            };
                        
            if(serverEntry) {
                if(bootstrap.isStockMap(serverEntry->map)) {
                    launch();
                    return;
                }
                

                QString exePath = bootstrap.programExePath();
                QFileInfo exeInfo(exePath);
                auto contentDir = QDir(exeInfo.dir());
                contentDir.cdUp();
                contentDir.cdUp();
                contentDir.cd("Content");
                auto zipFilePath = contentDir.absoluteFilePath(serverEntry->map + ".zip");
                
                if(QFile::exists(zipFilePath)) {
                    launch();
                    return;
                }

                Download mapDownload;
                mapDownload.setTarget("https://ut.rushbase.net/customcontent/Data/" + serverEntry->map + ".zip");
                QProgressDialog dialog("Downloading map: " + serverEntry->map, "Cancel", 0, 100);
                
                QFile zipFile(zipFilePath);
                zipFile.open(QIODevice::WriteOnly);
                
                int httpCode = 200;
                connect(&mapDownload, &Download::error, [&](int code) {
                    httpCode = code;
                    if(code != 200) {
                        zipFile.remove();
                        QMessageBox::critical(nullptr, "Unable to download map", QString("Got code %1 while trying to download map:<br>%2").arg(code).arg(serverEntry->map));
                    }
                });
                
                connect(&mapDownload, &Download::chunk, [&](QByteArray chunk) {
                    qDebug() << "Reading!\n";
                    zipFile.write(chunk);
                });
                connect(&mapDownload, &Download::progress, [&](double progress) {
                    dialog.setValue(100*progress);
                    if(progress == 1.0) {
                        dialog.accept();
                    }
                });
                
                
                mapDownload.download();
                qDebug() << "Downloading map " << serverEntry->map;
                if(!dialog.exec() || httpCode != 200) {
                    zipFile.remove(); // remove unfinished download
                    return;
                }
                zipFile.close();
                
                QProgressDialog installDialog("Installing map: " + serverEntry->map, "", 0, 100);
                installDialog.setWindowModality(Qt::ApplicationModal);
                installDialog.show();
                installDialog.setValue(0);
                
                qDebug() << "Installed!!\n";
                QuaZip zip(zipFilePath);
                
                auto textCodec = QTextCodec::codecForName("TSCII");
                zip.setFileNameCodec(textCodec);
                zip.setCommentCodec(textCodec);
                zip.open(QuaZip::mdUnzip);

                QuaZipFile file(&zip);

                size_t totalSize = 0;
                for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile()) {
                    QuaZipFileInfo info;
                    zip.getCurrentFileInfo(&info);
                    totalSize += info.uncompressedSize;
                }
                qDebug() << "Total size " << totalSize;
                size_t accumulatedSize = 0;
                /* TODO!!!!: this whole thing needs to be redone asynchronously */
                for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile()) {
                    file.open(QIODevice::ReadOnly);
                    //same functionality as QIODevice::readData() -- data is a char*, maxSize is qint64
                    //file.readData(data,maxSize);
                    QString filename = file.getActualFileName();
                    if(file.isOpen()) {
                        qApp->processEvents();
                        qDebug() << installDialog.isVisible() << installDialog.value();
                        if(!installDialog.isVisible() && installDialog.value() != 100 && installDialog.value() != -1)
                            return;
                        bool isDir = (filename.right(1) == "/");
                        if(isDir) {
                            contentDir.mkpath(filename);
                        } else {
                            QFile f(contentDir.absoluteFilePath(filename));
                            f.open(QIODevice::WriteOnly);
                            auto data = file.readAll();
                            accumulatedSize += data.size();
                            qDebug() << accumulatedSize;
                            installDialog.setValue(100 * (double)accumulatedSize / totalSize);
                            qApp->processEvents();
                            qDebug() << installDialog.isVisible() << installDialog.value();
                            if(!installDialog.isVisible() && installDialog.value() != 100 && installDialog.value() != -1)
                                return;

                            f.write(data);
                        }
                        qDebug() << file.getActualFileName() << isDir;
                        
                        //do something with the data
                        if(file.isOpen())
                            file.close();
                        qApp->processEvents();
                        qDebug() << installDialog.isVisible() << installDialog.value();
                        if(!installDialog.isVisible() && installDialog.value() != 100 && installDialog.value() != -1)
                            return;
                    }
                    else {
                        qDebug() << "Cannot open" << filename << "inside zip";;
                    }
                }
                qDebug() << "Closing zip\n";
                zip.close();

                launch();
            }            
        }
    });
    
    disconnect(&bootstrap, &Bootstrap::ready, this, &UTLauncher::prepareConfig);
    
    connect(&bootstrap, &Bootstrap::ready, this, [=] {
        browser->setMOTD(bootstrap.MOTD());
    });
    
    connect(browser, &ServerBrowser::openSettings, openSettings);
    
    browser->setEditorSupport(hasEditorSupport());
    
    browser->setHideOnClose(settings.value("MinimizeToTrayOnClose", false).toBool());
    
    systemTray.setToolTip("UTLauncher");
    auto systemTrayMenu = new QMenu(browser);
    
    auto showBrowser = new QAction(awesome->icon(fa::listalt), "Server List", this);
    connect(showBrowser, &QAction::triggered, [=]() {
        browser->showNormal();
        browser->raise();
        browser->activateWindow();
    });
    
    auto runUTAction = new QAction(awesome->icon( fa::gamepad ),"Run UT", this);
    connect(runUTAction, &QAction::triggered, [=]() {
        QString exePath = bootstrap.programExePath();
        if(!exePath.length()) {
            browser->show();
            openSettings();
            return;
        }
        QProcess::startDetached(exePath
#ifdef LAUNCH_WITH_UE4
        , QStringList() << "UnrealTournament" << "-SaveToUserDir"
#endif
        );
    });

    auto runEditorAction = new QAction(awesome->icon( fa::code ),"Run Editor", this);
    connect(runEditorAction, &QAction::triggered, [=]() {
        QString editorPath = bootstrap.editorExePath();
        QString projectPath = bootstrap.projectPath();
        QProcess::startDetached(editorPath, QStringList() << projectPath);
    });
    

    auto quitAction = new QAction(awesome->icon( fa::signout ),"Quit", this);
    connect(quitAction, &QAction::triggered, [=]() {
        QApplication::quit();
    });
    
    systemTrayMenu->addAction(showBrowser);
    systemTrayMenu->addSeparator();
    systemTrayMenu->addAction(runUTAction);
    systemTrayMenu->addAction(runEditorAction);
    systemTrayMenu->addSeparator();
    systemTrayMenu->addAction(quitAction);
    
    systemTray.setContextMenu(systemTrayMenu);
    systemTray.show();
    
    connect(&systemTray, &QSystemTrayIcon::activated, [=](QSystemTrayIcon::ActivationReason reason) {
        qApp->setQuitOnLastWindowClosed(true);
        
        runEditorAction->setVisible(hasEditorSupport());
        
        switch(reason) {
            
            case QSystemTrayIcon::Trigger:
            {
                if(browser->isHidden()) {
                    browser->show();
                } else {
                    browser->hide();
                }
                break;
            }

        }
    });
    
}
Пример #12
0
DiskBrowser::DiskBrowser() : QbWindow(config.geometry.diskBrowser) {
  setObjectName("disk-browser");
  resize(720, 480);

  layout = new QVBoxLayout;
  layout->setMargin(Style::WindowMargin);
  layout->setSpacing(Style::WidgetSpacing);
  setLayout(layout);

  topLayout = new QHBoxLayout;
  layout->addLayout(topLayout);

  browseLayout = new QVBoxLayout;
  topLayout->addLayout(browseLayout);

  pathLayout = new QHBoxLayout;
  browseLayout->addLayout(pathLayout);

  path = new QComboBox;
  path->setEditable(true);
  path->setMinimumContentsLength(16);
  path->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
  path->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
  pathLayout->addWidget(path);

  newFolder = new QPushButton;
  newFolder->setIconSize(QSize(16, 16));
  newFolder->setIcon(QIcon(":/16x16/folder-new.png"));
  pathLayout->addWidget(newFolder);

  view = new DiskBrowserView;
  view->setIconSize(QSize(16, 16));
  browseLayout->addWidget(view);

  panelLayout = new QVBoxLayout;
  topLayout->addLayout(panelLayout);

  group = new QGroupBox;
  panelLayout->addWidget(group);

  groupLayout = new QVBoxLayout;
  group->setLayout(groupLayout);

  info = new QLabel;
  info->setFixedWidth(256);
  groupLayout->addWidget(info);

  image = new DiskBrowserImage;
  image->setFixedSize(256, 239);
  groupLayout->addWidget(image);

  spacer = new QWidget;
  spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
  groupLayout->addWidget(spacer);

  applyPatch = new QCheckBox("Apply UPS patch");
  applyPatch->setChecked(true);
  applyPatch->setEnabled(false);
  groupLayout->addWidget(applyPatch);

  controlLayout = new QHBoxLayout;
  layout->addLayout(controlLayout);

  filter = new QComboBox;
  filter->setMinimumContentsLength(16);
  filter->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
  filter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
  controlLayout->addWidget(filter);

  options = new QPushButton("Options");
  controlLayout->addWidget(options);

  menu = new QMenu;
  options->setMenu(menu);

  menu->addAction(showPanel = new QbCheckAction("Show Side Panel", 0));
  showPanel->setChecked(config.diskBrowser.showPanel);

  ok = new QPushButton("Ok");
  ok->setEnabled(false);
  controlLayout->addWidget(ok);

  cancel = new QPushButton("Cancel");
  controlLayout->addWidget(cancel);

  model = new QFileSystemModel;
  model->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
  model->setNameFilterDisables(false);

  view->setModel(model);
  view->setExpandsOnDoubleClick(false);
  view->setAllColumnsShowFocus(true);
  view->setUniformRowHeights(true);
  view->setSortingEnabled(true);
  view->sortByColumn(0, Qt::AscendingOrder);
  view->setColumnHidden(1, true);
  view->setColumnHidden(2, true);
  view->setColumnHidden(3, true);
  view->setHeaderHidden(true);

  folderCreator = new FolderCreator;

  connect(newFolder, SIGNAL(released()), folderCreator, SLOT(show()));
  connect(view, SIGNAL(cdUp()), this, SLOT(cdUp()));
  connect(view, SIGNAL(activated(const QModelIndex&)), this, SLOT(activateItem(const QModelIndex&)));
  connect(view, SIGNAL(changed(const QModelIndex&)), this, SLOT(changeItem(const QModelIndex&)));
  connect(ok, SIGNAL(released()), this, SLOT(loadSelected()));
  connect(cancel, SIGNAL(released()), this, SLOT(close()));

  connect(showPanel, SIGNAL(triggered()), this, SLOT(toggleShowPanel()));
}
Пример #13
0
void FileMainWindow::setup()
{
    QSplitter *splitter = new QSplitter( this );

    dirlist = new DirectoryView( splitter, "dirlist", TRUE );
    dirlist->addColumn( "Name" );
    dirlist->addColumn( "Type" );
    Directory *root = new Directory( dirlist, "/" );
    root->setOpen( TRUE );
    splitter->setResizeMode( dirlist, QSplitter::KeepSize );

    fileview = new QtFileIconView( "/", splitter );
    fileview->setSelectionMode( QIconView::Extended );

    setCentralWidget( splitter );

    QToolBar *toolbar = new QToolBar( this, "toolbar" );
    setRightJustification( TRUE );

    (void)new QLabel( tr( " Path: " ), toolbar );

    pathCombo = new QComboBox( TRUE, toolbar );
    pathCombo->setAutoCompletion( TRUE );
    toolbar->setStretchableWidget( pathCombo );
    connect( pathCombo, SIGNAL( activated( const QString & ) ),
	     this, SLOT ( changePath( const QString & ) ) );

    toolbar->addSeparator();

    QPixmap pix;

    pix = QPixmap( cdtoparent_xpm );
    upButton = new QToolButton( pix, "One directory up", QString::null,
				this, SLOT( cdUp() ), toolbar, "cd up" );

    pix = QPixmap( newfolder_xpm );
    mkdirButton = new QToolButton( pix, "New Folder", QString::null,
				   this, SLOT( newFolder() ), toolbar, "new folder" );

    connect( dirlist, SIGNAL( folderSelected( const QString & ) ),
	     fileview, SLOT ( setDirectory( const QString & ) ) );
    connect( fileview, SIGNAL( directoryChanged( const QString & ) ),
	     this, SLOT( directoryChanged( const QString & ) ) );
    connect( fileview, SIGNAL( startReadDir( int ) ),
	     this, SLOT( slotStartReadDir( int ) ) );
    connect( fileview, SIGNAL( readNextDir() ),
	     this, SLOT( slotReadNextDir() ) );
    connect( fileview, SIGNAL( readDirDone() ),
	     this, SLOT( slotReadDirDone() ) );

    setDockEnabled( DockLeft, FALSE );
    setDockEnabled( DockRight, FALSE );

    label = new QLabel( statusBar() );
    statusBar()->addWidget( label, 2, TRUE );
    progress = new QProgressBar( statusBar() );
    statusBar()->addWidget( progress, 1, TRUE );

    connect( fileview, SIGNAL( enableUp() ),
	     this, SLOT( enableUp() ) );
    connect( fileview, SIGNAL( disableUp() ),
	     this, SLOT( disableUp() ) );
    connect( fileview, SIGNAL( enableMkdir() ),
	     this, SLOT( enableMkdir() ) );
    connect( fileview, SIGNAL( disableMkdir() ),
	     this, SLOT( disableMkdir() ) );
}