Пример #1
0
void
MediumPluginManager::newDevice()
{
    DEBUG_BLOCK
    ManualDeviceAdder* mda = new ManualDeviceAdder( this );
    if( mda->exec() == QDialog::Accepted && mda->successful() && mda->getMedium() != 0 )
    {
        if( amaroK::config( "MediaBrowser" )->readEntry( mda->getMedium()->id() ) != QString::null )
        {
            //abort!  Can't have the same device defined twice...should never
            //happen due to name checking earlier...right?
            amaroK::StatusBar::instance()->longMessageThreadSafe( i18n("Sorry, you cannot define two devices\n"
                                                                       "with the same name and mountpoint!") );
        }
        else
        {
            Medium *newdev = mda->getMedium();
            amaroK::config( "MediaBrowser" )->writeEntry( newdev->id(), mda->getPlugin() );
            DeviceManager::instance()->addManualDevice( newdev );
            m_newDevMap[newdev->id()] = newdev;
            detectDevices();
        }
    }
    delete mda;
    slotChanged();
}
Пример #2
0
bool MediaImpl::ensureMediumMounted(Medium &medium)
{
    if(medium.id().isEmpty())
    {
        m_lastErrorCode = KIO::ERR_COULD_NOT_MOUNT;
        m_lastErrorMessage = i18n("No such medium.");
        return false;
    }

    if(medium.needMounting())
    {
        m_lastErrorCode = 0;

        mp_mounting = &medium;


        /*
        KIO::Job* job = KIO::mount(false, 0,
                                   medium.deviceNode(),
                                   medium.mountPoint());
        job->setAutoWarningHandlingEnabled(false);
        connect( job, SIGNAL( result( KIO::Job * ) ),
                 this, SLOT( slotMountResult( KIO::Job * ) ) );
        connect( job, SIGNAL( warning( KIO::Job *, const QString & ) ),
                 this, SLOT( slotWarning( KIO::Job *, const QString & ) ) );
        */
        kapp->dcopClient()->connectDCOPSignal("kded", "mediamanager", "mediumChanged(QString, bool)", "mediaimpl", "slotMediumChanged(QString)",
                                              false);

        DCOPRef mediamanager("kded", "mediamanager");
        DCOPReply reply = mediamanager.call("mount", medium.id());
        if(reply.isValid())
            reply.get(m_lastErrorMessage);
        else
            m_lastErrorMessage = i18n("Internal Error");
        if(!m_lastErrorMessage.isEmpty())
            m_lastErrorCode = KIO::ERR_SLAVE_DEFINED;
        else
        {
            qApp->eventLoop()->enterLoop();
        }

        mp_mounting = 0L;

        kapp->dcopClient()->disconnectDCOPSignal("kded", "mediamanager", "mediumChanged(QString, bool)", "mediaimpl", "slotMediumChanged(QString)");

        return m_lastErrorCode == 0;
    }

    return true;
}
Пример #3
0
bool MediaImpl::statMedium(const QString &name, KIO::UDSEntry &entry)
{
    kdDebug(1219) << "MediaImpl::statMedium: " << name << endl;

    DCOPRef mediamanager("kded", "mediamanager");
    DCOPReply reply = mediamanager.call("properties", name);

    if(!reply.isValid())
    {
        m_lastErrorCode = KIO::ERR_SLAVE_DEFINED;
        m_lastErrorMessage = i18n("The KDE mediamanager is not running.");
        return false;
    }

    Medium m = Medium::create(reply);

    if(m.id().isEmpty())
    {
        entry.clear();
        return false;
    }

    createMediumEntry(entry, m);

    return true;
}
Пример #4
0
bool KFileMediaPlugin::readInfo(KFileMetaInfo &info, uint /*what*/)
{
        const Medium medium = askMedium(info);

	kdDebug() << "KFileMediaPlugin::readInfo " << medium.id() << endl;
 
	if (medium.id().isNull()) return false;
	
	QString mount_point = medium.mountPoint();
	KURL base_url = medium.prettyBaseURL();
	QString device_node = medium.deviceNode();

	KFileMetaInfoGroup group = appendGroup(info, "mediumInfo");

	if (base_url.isValid())
	{
		appendItem(group, "baseURL", base_url.prettyURL());
	}

	if (!device_node.isEmpty())
	{
		appendItem(group, "deviceNode", device_node);
	}

	if (!mount_point.isEmpty() && medium.isMounted())
	{
		m_total = 0;
		m_used = 0;
		m_free = 0;

		struct statvfs vfs;
		memset(&vfs, 0, sizeof(vfs));

		if ( ::statvfs(QFile::encodeName(mount_point), &vfs) != -1 )
		{
			m_total = static_cast<KIO::filesize_t>(vfs.f_blocks) * static_cast<KIO::filesize_t>(vfs.f_frsize);
			m_free = static_cast<KIO::filesize_t>(vfs.f_bavail) * static_cast<KIO::filesize_t>(vfs.f_frsize);
			m_used = m_total - m_free;

			int percent = 0;
			int length = 0;

			if (m_total != 0)
			{
				percent = 100 * m_used / m_total;
				length = 150 * m_used / m_total;
			}

			appendItem(group, "free", m_free);
			appendItem(group, "used", m_used);
			appendItem(group, "total", m_total);

			group = appendGroup(info, "mediumSummary");

			appendItem(group, "percent", QString("%1%").arg(percent));

			QPixmap bar(150, 20);
			QPainter p(&bar);

			p.fillRect(0, 0, length, 20, Qt::red);
			p.fillRect(length, 0, 150-length, 20, Qt::green);

			QColorGroup cg = QApplication::palette().active();

			QApplication::style().drawPrimitive(QStyle::PE_Panel, &p,
							    QRect(0, 0, 150, 20), cg,
							    QStyle::Style_Sunken);

			appendItem( group, "thumbnail", bar );
		}
	}

	return true;
}