示例#1
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Settings
    m_settings = new VSettings("org.hawaii.desktop");
    connect(m_settings, SIGNAL(changed()),
            this, SLOT(settingsChanged()));

    // Connect signals
    connect(ui->actionNewTab, SIGNAL(triggered()),
            this, SLOT(slotNewTab()));
    connect(ui->actionNewWindow, SIGNAL(triggered()),
            this, SLOT(slotNewWindow()));
    connect(ui->actionCloseTab, SIGNAL(triggered()),
            this, SLOT(slotCloseCurrentTab()));
    connect(ui->actionOpenFileManager, SIGNAL(triggered()),
            this, SLOT(slotOpenFileManager()));
    connect(ui->actionQuit, SIGNAL(triggered()),
            this, SLOT(close()));
    connect(ui->actionCopy, SIGNAL(triggered()),
            this, SLOT(slotCopy()));
    connect(ui->actionPaste, SIGNAL(triggered()),
            this, SLOT(slotPaste()));
    connect(ui->actionFind, SIGNAL(triggered()),
            this, SLOT(slotFind()));
    connect(ui->actionAbout, SIGNAL(triggered()),
            this, SLOT(slotAbout()));
    connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)),
            this, SLOT(slotCloseTab(int)));

    // Start with a tab
    slotNewTab();
}
示例#2
0
void PanelBrowserMenu::initialize()
{
    _lastpress = QPoint(-1, -1);

    // don't change menu if already visible
    if (isVisible())
        return;

    if (_dirty) {
        // directory content changed while menu was visible
        slotClear();
        setInitialized(false);
        _dirty = false;
    }

    if (initialized()) return;
    setInitialized(true);

    // start watching if not already done
    if (!_dirWatch.contains(path()))
        _dirWatch.addDir( path() );

    // setup icon map
    initIconMap();

    // clear maps
    _filemap.clear();
    _mimemap.clear();

    QDir::Filters filter = QDir::Dirs | QDir::Files;
    if (KickerSettings::showHiddenFiles())
    {
        filter |= QDir::Hidden;
    }

    QDir dir(path(), QString(), QDir::DirsFirst | QDir::Name | QDir::IgnoreCase, filter);

    // does the directory exist?
    if (!dir.exists()) {
        insertItem(i18n("Failed to Read Folder"));
	return;
    }

    // get entry list
    QFileInfoList list = dir.entryInfoList();

    KUrl url;
    url.setPath(path());
    if (!KAuthorized::authorizeUrlAction("list", KUrl(), url))
    {
        insertItem(i18n("Not Authorized to Read Folder"));
        return;
    }

    // insert file manager and terminal entries
    // only the first part menu got them
    if(_startid == 0 && !_filesOnly) {
       // FIXME: no more menu titles so NOW WHAT?!
       // insertTitle(path());
       insertItem(CICON("kfm"), i18n("Open in File Manager"), this, SLOT(slotOpenFileManager()));
        if (KAuthorized::authorizeKAction("shell_access"))
            insertItem(CICON("terminal"), i18n("Open in Terminal"), this, SLOT(slotOpenTerminal()));
    }


    bool first_entry = true;
    bool dirfile_separator = false;
    unsigned int item_count = 0;
    int run_id = _startid;

    // get list iterator
    QFileInfoList::iterator it = list.begin();

    // jump to startid
    it += _startid;

    // iterate over entry list
    for (; it != list.end(); ++it)
    {
        // bump id
        run_id++;

        QFileInfo fi = *it;
        // handle directories
        if (fi.isDir())
        {
            QString name = fi.fileName();

            // ignore . and .. entries
            if (name == "." || name == "..") continue;

            QPixmap icon;
            QString path = fi.absoluteFilePath();

            // parse .directory if it does exist
            if (QFile::exists(path + "/.directory")) {

                KDesktopFile c(path + "/.directory");
                const KConfigGroup cg = c.desktopGroup();
                QString iconPath = cg.readEntry("Icon");

                if ( iconPath.startsWith("./") )
                    iconPath = path + '/' + iconPath.mid(2);

                icon = KIconLoader::global()->loadIcon(iconPath,
                                                    KIconLoader::Small, KIconLoader::SizeSmall,
                                                    KIconLoader::DefaultState, QStringList(), 0, true);
                if(icon.isNull())
                    icon = CICON("folder");
                name = cg.readEntry("Name", name);
            }

            // use cached folder icon for directories without special icon
            if (icon.isNull())
                icon = CICON("folder");

            // insert separator if we are the first menu entry
            if(first_entry) {
                if (_startid == 0 && !_filesOnly)
                    addSeparator();
                first_entry = false;
            }

            // append menu entry
            PanelBrowserMenu *submenu = new PanelBrowserMenu(path, this);
            submenu->_filesOnly = _filesOnly;
            append(icon, name, submenu);

            // bump item count
            item_count++;

            dirfile_separator = true;
        }
        // handle files
        else if(fi.isFile())
        {
            QString name = fi.fileName();
            QString title = KIO::decodeFileName(name);

            QPixmap icon;
            QString path = fi.absoluteFilePath();

            bool mimecheck = false;

            // .desktop files
            if(KDesktopFile::isDesktopFile(path))
            {
                KDesktopFile c( path );
                const KConfigGroup cg = c.desktopGroup();
                title = cg.readEntry("Name", title);

                QString s = cg.readEntry("Icon");
                if(!_icons->contains(s)) {
                    icon  = KIconLoader::global()->loadIcon(s, KIconLoader::Small, KIconLoader::SizeSmall,
                                                         KIconLoader::DefaultState, QStringList(), 0, true);

                    if(icon.isNull()) {
                        QString type = cg.readEntry("Type", "Application");
                        if (type == "Directory")
                            icon = CICON("folder");
                        else if (type == "Mimetype")
                            icon = CICON("txt");
                        else if (type == "FSDevice")
                            icon = CICON("chardevice");
                        else
                            icon = CICON("exec");
                    }
                    else
                        _icons->insert(s, icon);
                }
                else
                    icon = CICON(s);
            }
            else {
                // set unknown icon
                icon = CICON("unknown");

                // mark for delayed mimetime check
                mimecheck = true;
            }

            // insert separator if we are the first menu entry
            if(first_entry) {
                if(_startid == 0 && !_filesOnly)
                    addSeparator();
                first_entry = false;
            }

            // insert separator if we we first file after at least one directory
            if (dirfile_separator) {
                addSeparator();
                dirfile_separator = false;
            }

            // append file entry
            append(icon, title, name, mimecheck);

            // bump item count
            item_count++;
        }

        if (item_count == KickerSettings::maxEntries2())
        {
            // Only insert a "More" item if there are actually more items.
            ++it;
            if( it != list.end() ) {
                addSeparator();
                append(CICON("kdisknav"), i18n("More"), new PanelBrowserMenu(path(), this, run_id));
            }
            break;
        }
    }

#if 0
    // WABA: tear off handles don't work together with dynamically updated
    // menus. We can't update the menu while torn off, and we don't know
    // when it is torn off.
    if(KGlobalSettings::insertTearOffHandle() && item_count > 0)
        insertTearOffHandle();
#endif

    adjustSize();

    QString dirname = path();

    int maxlen = contentsRect().width() - 40;
    if(item_count == 0)
        maxlen = fontMetrics().width(dirname);

    if (fontMetrics().width(dirname) > maxlen) {
        while ((!dirname.isEmpty()) && (fontMetrics().width(dirname) > (maxlen - fontMetrics().width("..."))))
            dirname = dirname.remove(0, 1);
        dirname.prepend("...");
    }
    setWindowTitle(dirname);

    // setup and start delayed mimetype check timer
    if(_mimemap.count() > 0) {

        if(!_mimecheckTimer)
            _mimecheckTimer = new QTimer(this);

        connect(_mimecheckTimer, SIGNAL(timeout()), SLOT(slotMimeCheck()));
        _mimecheckTimer->start(0);
    }
}