示例#1
0
qulonglong totalMemory()
{
    // Retrieve and return in bytes the total amount of physical memory

    qulonglong res = 0;

#if defined(Q_OS_WIN)
    MEMORYSTATUSEX memoryStatus;

    memoryStatus.dwLength = sizeof(memoryStatus);

    GlobalMemoryStatusEx(&memoryStatus);

    res = qulonglong(memoryStatus.ullTotalPhys);
#elif defined(Q_OS_LINUX)
    res = qulonglong(sysconf(_SC_PHYS_PAGES))*qulonglong(sysconf(_SC_PAGESIZE));
#elif defined(Q_OS_MAC)
    int mib[2];

    mib[0] = CTL_HW;
    mib[1] = HW_MEMSIZE;

    size_t len = sizeof(res);

    sysctl(mib, 2, &res, &len, 0, 0);
#else
    #error Unsupported platform
#endif

    return res;
}
示例#2
0
/* static */
int UIWizardNewVDPage3::sizeMBToSlider(qulonglong uValue, int iSliderScale)
{
    int iPower = log2i(uValue);
    qulonglong uTickMB = qulonglong (1) << iPower;
    qulonglong uTickMBNext = qulonglong (1) << (iPower + 1);
    int iStep = (uValue - uTickMB) * iSliderScale / (uTickMBNext - uTickMB);
    return iPower * iSliderScale + iStep;
}
示例#3
0
/* static */
qulonglong UIWizardNewVDPage3::sliderToSizeMB(int uValue, int iSliderScale)
{
    int iPower = uValue / iSliderScale;
    int iStep = uValue % iSliderScale;
    qulonglong uTickMB = qulonglong (1) << iPower;
    qulonglong uTickMBNext = qulonglong (1) << (iPower + 1);
    return uTickMB + (uTickMBNext - uTickMB) * iStep / iSliderScale;
}
示例#4
0
QT_BEGIN_NAMESPACE

static QByteArray debugWinStyle(DWORD style)
{
    QByteArray rc = "0x";
    rc += QByteArray::number(qulonglong(style), 16);
    if (style & WS_POPUP)
        rc += " WS_POPUP";
    if (style & WS_CHILD)
        rc += " WS_CHILD";
    if (style & WS_OVERLAPPED)
        rc += " WS_OVERLAPPED";
    if (style & WS_CLIPSIBLINGS)
        rc += " WS_CLIPSIBLINGS";
    if (style & WS_CLIPCHILDREN)
        rc += " WS_CLIPCHILDREN";
    if (style & WS_THICKFRAME)
        rc += " WS_THICKFRAME";
    if (style & WS_DLGFRAME)
        rc += " WS_DLGFRAME";
    if (style & WS_SYSMENU)
        rc += " WS_SYSMENU";
    if (style & WS_MINIMIZEBOX)
        rc += " WS_MINIMIZEBOX";
    if (style & WS_MAXIMIZEBOX)
        rc += " WS_MAXIMIZEBOX";
    return rc;
}
QMimeData * KPrCustomSlideShowsModel::mimeData(const QModelIndexList &indexes) const
{
    // check if there is data to encode
    if (! indexes.count()) {
        return 0;
    }

    // check if we support a format
    const QStringList types = mimeTypes();
    if (types.isEmpty()) {
        return 0;
    }

    QMimeData *data = new QMimeData();
    QByteArray encoded;
    QDataStream stream(&encoded, QIODevice::WriteOnly);

    // encode the data & order slides
    QModelIndexList::ConstIterator it = indexes.begin();

    QMap<int, KoPAPageBase*> map;
    for( ; it != indexes.end(); ++it) {
        map.insert(m_customSlideShows->indexByPage(m_activeCustomSlideShowName, (KoPAPageBase*)it->internalPointer()),
                   (KoPAPageBase*)it->internalPointer());
    }

    QList<KoPAPageBase *> slides = map.values();

    foreach (KoPAPageBase *slide, slides) {
        stream << QVariant::fromValue(qulonglong((void*)slide));
    }
/*!
    \fn QVersionNumber QVersionNumber::fromString(const QString &string,
                                                  int *suffixIndex)

    Constructs a QVersionNumber from a specially formatted \a string of
    non-negative decimal numbers delimited by '.'.

    Once the numerical segments have been parsed, the remainder of the string
    is considered to be the suffix string.  The start index of that string will be
    stored in \a suffixIndex if it is not null.

    \snippet qversionnumber/main.cpp 3

    \sa isNull()
*/
QVersionNumber QVersionNumber::fromString(const QString &string, int *suffixIndex)
{
    QVector<int> seg;

    const QByteArray cString(string.toLatin1());

    const char *start = cString.constData();
    const char *end = start;
    const char *lastGoodEnd = start;
    const char *endOfString = cString.constData() + cString.size();

    do {
        bool ok = false;
        const qulonglong value = qstrtoull(start, &end, 10, &ok);
        if (!ok || value > qulonglong(std::numeric_limits<int>::max()))
            break;
        seg.append(int(value));
        start = end + 1;
        lastGoodEnd = end;
    } while (start < endOfString && (end < endOfString && *end == '.'));

    if (suffixIndex)
        *suffixIndex = int(lastGoodEnd - cString.constData());

    return QVersionNumber(qMove(seg));
}
示例#7
0
void setNlaSolver(const QString &pRuntimeAddress, NlaSolver *pGlobalNlaSolver)
{
    // Keep track of the runtime's NLA solver

    QByteArray runtimeAddress = pRuntimeAddress.toUtf8();

    qApp->setProperty(runtimeAddress.constData(), qulonglong(pGlobalNlaSolver));
}
示例#8
0
/*
    \reimp
*/
void QGraphicsVideoItem::paint(
        QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_D(QGraphicsVideoItem);

    Q_UNUSED(option);
    Q_UNUSED(widget);

    if (widget)
        d->watcher->setActiveWindow(widget->window());

    if (d->surface && d->rendererControl && d->updatePaintDevice) {
        d->updatePaintDevice = false;

#ifdef ENABLE_OVERLAY
        if (widget)
            d->rendererControl->setProperty("winId", qulonglong(widget->winId()));
#endif

#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
        if (widget)
            connect(widget, SIGNAL(destroyed()), d->surface, SLOT(viewportDestroyed()));

        d->surface->setGLContext(const_cast<QGLContext *>(QGLContext::currentContext()));
#endif
        if (d->rendererControl->surface() != d->surface)
            d->rendererControl->setSurface(d->surface);
    }


    //overlay doesn't work reliably

    //check if the item is obscured:
#ifdef ENABLE_OVERLAY
    if (!isObscured()) {
        bool obscured = false;

        if (scene()) {
            foreach (QGraphicsItem *item,
                     scene()->items(mapToScene(boundingRect()), Qt::IntersectsItemBoundingRect) ) {
                if (item->flags() & QGraphicsItem::ItemHasNoContents)
                    continue;

                if (item == this)
                    break;

                if (collidesWithItem(item)) {
                    obscured = true;
                    break;
                }
            }
        }

        d->rendererControl->setProperty("overlayEnabled", !obscured);
    }
示例#9
0
static QByteArray debugWinExStyle(DWORD exStyle)
{
    QByteArray rc = "0x";
    rc += QByteArray::number(qulonglong(exStyle), 16);
    if (exStyle & WS_EX_TOOLWINDOW)
        rc += " WS_EX_TOOLWINDOW";
    if (exStyle & WS_EX_CONTEXTHELP)
        rc += " WS_EX_CONTEXTHELP";
    if (exStyle & WS_EX_LAYERED)
        rc += " WS_EX_LAYERED";
    return rc;
}
示例#10
0
qulonglong freeMemory()
{
    // Retrieve and return in bytes the available amount of physical memory

    qulonglong res = 0;

#if defined(Q_OS_WIN)
    MEMORYSTATUSEX memoryStatus;

    memoryStatus.dwLength = sizeof(memoryStatus);

    GlobalMemoryStatusEx(&memoryStatus);

    res = qulonglong(memoryStatus.ullAvailPhys);
#elif defined(Q_OS_LINUX)
    res = qulonglong(sysconf(_SC_AVPHYS_PAGES))*qulonglong(sysconf(_SC_PAGESIZE));
#elif defined(Q_OS_MAC)
    vm_statistics_data_t vmStats;
    mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;

    host_statistics(mach_host_self(), HOST_VM_INFO,
                    host_info_t(&vmStats), &infoCount);

    res = (qulonglong(vmStats.free_count)+qulonglong(vmStats.inactive_count))*qulonglong(vm_page_size);
#else
    #error Unsupported platform
#endif

    return res;
}
static QVariant convertValue(const PROPVARIANT& var)
{
    QVariant value;
    switch (var.vt) {
    case VT_LPWSTR:
        value = QString::fromUtf16(reinterpret_cast<const ushort*>(var.pwszVal));
        break;
    case VT_UI4:
        value = uint(var.ulVal);
        break;
    case VT_UI8:
        value = qulonglong(var.uhVal.QuadPart);
        break;
    case VT_BOOL:
        value = bool(var.boolVal);
        break;
    case VT_FILETIME:
        SYSTEMTIME sysDate;
        if (!FileTimeToSystemTime(&var.filetime, &sysDate))
            break;
        value = QDate(sysDate.wYear, sysDate.wMonth, sysDate.wDay);
        break;
    case VT_STREAM:
    {
        STATSTG stat;
        if (FAILED(var.pStream->Stat(&stat, STATFLAG_NONAME)))
            break;
        void *data = malloc(stat.cbSize.QuadPart);
        ULONG read = 0;
        if (FAILED(var.pStream->Read(data, stat.cbSize.QuadPart, &read))) {
            free(data);
            break;
        }
        value = QImage::fromData(reinterpret_cast<const uchar*>(data), read);
        free(data);
    }
        break;
    case VT_VECTOR | VT_LPWSTR:
        QStringList vList;
        for (ULONG i = 0; i < var.calpwstr.cElems; ++i)
            vList.append(QString::fromUtf16(reinterpret_cast<const ushort*>(var.calpwstr.pElems[i])));
        value = vList;
        break;
    }
    return value;
}
示例#12
0
/*!
    Returns the string form of this work size, with components
    separated by 'x'.

    \sa fromString()
*/
QString QCLWorkSize::toString() const
{
    if (m_dim == 1) {
        return QString::number(qulonglong(m_sizes[0]));
    } else if (m_dim == 2) {
        return QString::number(qulonglong(m_sizes[0])) + QLatin1Char('x') +
               QString::number(qulonglong(m_sizes[1]));
    } else {
        return QString::number(qulonglong(m_sizes[0])) + QLatin1Char('x') +
               QString::number(qulonglong(m_sizes[1])) + QLatin1Char('x') +
               QString::number(qulonglong(m_sizes[2]));
    }
}
示例#13
0
static void oldGetDateFromJulianDay(double jd, int *year, int *month, int *day)
{
	int y, m, d;

	// put us in the right calendar day for the time of day.
	double fraction = jd - floor(jd);
	if (fraction >= .5)
	{
		jd += 1.0;
	}

	if (jd >= 2299161)
	{
		// Gregorian calendar starting from October 15, 1582
		// This algorithm is from Henry F. Fliegel and Thomas C. Van Flandern
		qulonglong ell, n, i, j;
		ell = qulonglong(floor(jd)) + 68569;
		n = (4 * ell) / 146097;
		ell = ell - (146097 * n + 3) / 4;
		i = (4000 * (ell + 1)) / 1461001;
		ell = ell - (1461 * i) / 4 + 31;
		j = (80 * ell) / 2447;
		d = ell - (2447 * j) / 80;
		ell = j / 11;
		m = j + 2 - (12 * ell);
		y = 100 * (n - 49) + i + ell;
	}
	else
	{
		// Julian calendar until October 4, 1582
		// Algorithm from Frequently Asked Questions about Calendars by Claus Toendering
		int julianDay = (int)floor(jd);
		julianDay += 32082;
		int dd = (4 * julianDay + 3) / 1461;
		int ee = julianDay - (1461 * dd) / 4;
		int mm = ((5 * ee) + 2) / 153;
		d = ee - (153 * mm + 2) / 5 + 1;
		m = mm + 3 - 12 * (mm / 10);
		y = dd - 4800 + (mm / 10);
	}
	*year = y;
	*month = m;
	*day = d;
}
SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent)
:   QWidget(parent), statsTimer(-1)
{
    setupUi(this);

#ifdef QT_NO_NETWORKINTERFACE
    interfaceName->setVisible(false);
    interfaceNameLabel->setVisible(false);
    interfaceGuid->setVisible(false);
    interfaceGuidLabel->setVisible(false);
#endif

    session = new QNetworkSession(config, this);

    connect(session, SIGNAL(stateChanged(QNetworkSession::State)),
            this, SLOT(updateSession()));
    connect(session, SIGNAL(error(QNetworkSession::SessionError)),
            this, SLOT(updateSessionError(QNetworkSession::SessionError)));

    updateSession();

    sessionId->setText(QString("0x%1").arg(qulonglong(session), 8, 16, QChar('0')));

    configuration->setText(session->configuration().name());

    connect(openSessionButton, SIGNAL(clicked()),
            this, SLOT(openSession()));
    connect(openSyncSessionButton, SIGNAL(clicked()),
            this, SLOT(openSyncSession()));
    connect(closeSessionButton, SIGNAL(clicked()),
            this, SLOT(closeSession()));
    connect(stopSessionButton, SIGNAL(clicked()),
            this, SLOT(stopSession()));
#if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
    connect(deleteSessionButton, SIGNAL(clicked()),
            this, SLOT(deleteSession()));
#endif
}
示例#15
0
void * globalInstance(const QString &pObjectName, void *pDefaultGlobalInstance)
{
    // Retrieve the 'global' instance of an object
    // Note: initially, the plan was to have a static instance of an object and
    //       return its address. However, this approach doesn't work on Windows
    //       and Linux (but does on OS X). Indeed, say that the Core plugin is
    //       required by two other plugins, then these two plugins won't get the
    //       same 'copy' of the Core plugin. (It seems like) each 'copy' gets
    //       its own address space. (This is not the case on OS X, (most likely)
    //       because of the way applications are bundled on that platform.) So,
    //       to address this issue, we keep track of the address of a 'global'
    //       instance using QSettings...

    QSettings settings(SettingsOrganization, SettingsApplication);
    qulonglong globalInstance;

    settings.beginGroup(SettingsGlobal);
        globalInstance = settings.value(pObjectName, 0).toULongLong();

        if (!globalInstance) {
            // There is no 'global' instance associated with the given object,
            // so use the object's default 'global' instance we were given

            globalInstance = qulonglong(pDefaultGlobalInstance);

            settings.setValue(pObjectName, QString::number(globalInstance));
            // Note #1: for some reasons, on OS X, QSettings doesn't handle
            //          qulonglong values properly, so we do it through a
            //          QString value instead...
            // Note #2: see https://bugreports.qt.io/browse/QTBUG-29681 for
            //          more information...
        }
    settings.endGroup();

    // Return the class's 'global' instance

    return (void *) globalInstance;
}
示例#16
0
bool QgsProject::write()
{
  clearError();

  // if we have problems creating or otherwise writing to the project file,
  // let's find out up front before we go through all the hand-waving
  // necessary to create all the Dom objects
  if ( !imp_->file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
  {
    imp_->file.close();         // even though we got an error, let's make
    // sure it's closed anyway

    setError( tr( "Unable to save to file %1" ).arg( imp_->file.fileName() ) );
    return false;
  }
  QFileInfo myFileInfo( imp_->file );
  if ( !myFileInfo.isWritable() )
  {
    // even though we got an error, let's make
    // sure it's closed anyway
    imp_->file.close();
    setError( tr( "%1 is not writable. Please adjust permissions (if possible) and try again." )
              .arg( imp_->file.fileName() ) );
    return false;
  }

  QDomImplementation DomImplementation;

  QDomDocumentType documentType =
    DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd",
                                          "SYSTEM" );
  std::auto_ptr < QDomDocument > doc =
    std::auto_ptr < QDomDocument > ( new QDomDocument( documentType ) );


  QDomElement qgisNode = doc->createElement( "qgis" );
  qgisNode.setAttribute( "projectname", title() );
  qgisNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );

  doc->appendChild( qgisNode );

  // title
  QDomElement titleNode = doc->createElement( "title" );
  qgisNode.appendChild( titleNode );

  QDomText titleText = doc->createTextNode( title() );  // XXX why have title TWICE?
  titleNode.appendChild( titleText );

  // let map canvas and legend write their information
  emit writeProject( *doc );

  // within top level node save list of layers
  QMap<QString, QgsMapLayer*> & layers = QgsMapLayerRegistry::instance()->mapLayers();

  // Iterate over layers in zOrder
  // Call writeXML() on each
  QDomElement projectLayersNode = doc->createElement( "projectlayers" );
  projectLayersNode.setAttribute( "layercount", qulonglong( layers.size() ) );

  QMap<QString, QgsMapLayer*>::iterator li = layers.begin();
  while ( li != layers.end() )
  {
    //QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer(*li);
    QgsMapLayer* ml = li.value();

    if ( ml )
    {
      QString externalProjectFile = layerIsEmbedded( ml->id() );
      QHash< QString, QPair< QString, bool> >::const_iterator emIt = mEmbeddedLayers.find( ml->id() );
      if ( emIt == mEmbeddedLayers.constEnd() )
      {
        ml->writeXML( projectLayersNode, *doc );
      }
      else //layer defined in an external project file
      {
        //only save embedded layer if not managed by a legend group
        if ( emIt.value().second )
        {
          QDomElement mapLayerElem = doc->createElement( "maplayer" );
          mapLayerElem.setAttribute( "embedded", 1 );
          mapLayerElem.setAttribute( "project", writePath( emIt.value().first ) );
          mapLayerElem.setAttribute( "id", ml->id() );
          projectLayersNode.appendChild( mapLayerElem );
        }
      }
    }
    li++;
  }

  qgisNode.appendChild( projectLayersNode );

  // now add the optional extra properties

  dump_( imp_->properties_ );

  QgsDebugMsg( QString( "there are %1 property scopes" ).arg( static_cast<int>( imp_->properties_.count() ) ) );

  if ( !imp_->properties_.isEmpty() ) // only worry about properties if we
    // actually have any properties
  {
    imp_->properties_.writeXML( "properties", qgisNode, *doc );
  }

  // now wrap it up and ship it to the project file
  doc->normalize();             // XXX I'm not entirely sure what this does

  //QString xml = doc->toString(4); // write to string with indentation of four characters
  // (yes, four is arbitrary)

  // const char * xmlString = xml; // debugger probe point
  // qDebug( "project file output:\n\n" + xml );

  QTextStream projectFileStream( &imp_->file );

  //projectFileStream << xml << endl;
  doc->save( projectFileStream, 4 );  // save as utf-8
  imp_->file.close();

  // check if the text stream had no error - if it does
  // the user will get a message so they can try to resolve the
  // situation e.g. by saving project to a volume with more space
  //
  if ( projectFileStream.pos() == -1  || imp_->file.error() != QFile::NoError )
  {
    setError( tr( "Unable to save to file %1. Your project "
                  "may be corrupted on disk. Try clearing some space on the volume and "
                  "check file permissions before pressing save again." )
              .arg( imp_->file.fileName() ) );
    return false;
  }

  dirty( false );               // reset to pristine state

  emit projectSaved();

  return true;
} // QgsProject::write
示例#17
0
void MessageWidget::fill(const std::string &msgId)
{
//	if (currMsgId == msgId) {
//		// message doesn't changed
//		return;
//	}

	currMsgId = msgId;

	if (currMsgId.empty()) {
		/* blank it */
		ui.dateText-> setText("");
		ui.toText->setText("");
		ui.fromText->setText("");
		ui.filesText->setText("");

		ui.ccLabel->setVisible(false);
		ui.ccText->setVisible(false);
		ui.ccText->clear();

		ui.bccLabel->setVisible(false);
		ui.bccText->setVisible(false);
		ui.bccText->clear();

		ui.subjectText->setText("");
		ui.msgList->clear();
		ui.msgText->clear();
		ui.msgText->resetImagesStatus(false);

		clearTagLabels();

		currMsgFlags = 0;

		return;
	}

	clearTagLabels();

	MessageInfo msgInfo;
	if (rsMail->getMessage(currMsgId, msgInfo) == false) {
		std::cerr << "MessageWidget::fill() Couldn't find Msg" << std::endl;
		return;
	}
	
	if (msgInfo.msgflags & RS_MSG_USER_REQUEST){
        ui.inviteFrame->show();
  	} else {
        ui.inviteFrame->hide();
  	}

	const std::list<FileInfo> &recList = msgInfo.files;
	std::list<FileInfo>::const_iterator it;

	ui.msgList->clear();

	QList<QTreeWidgetItem*> items;
	for (it = recList.begin(); it != recList.end(); ++it) {
		QTreeWidgetItem *item = new QTreeWidgetItem;
		item->setText(COLUMN_FILE_NAME, QString::fromUtf8(it->fname.c_str()));
		item->setText(COLUMN_FILE_SIZE, misc::friendlyUnit(it->size));
		item->setData(COLUMN_FILE_SIZE, Qt::UserRole, QVariant(qulonglong(it->size)) );
		item->setText(COLUMN_FILE_HASH, QString::fromStdString(it->hash.toStdString()));
		item->setTextAlignment( COLUMN_FILE_SIZE, Qt::AlignRight );

		/* add to the list */
		items.append(item);
	}

	/* add the items in! */
	ui.msgList->insertTopLevelItems(0, items);

	/* iterate through the sources */
	RetroShareLink link;
	QString text;

	for(std::set<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgto.begin(); pit != msgInfo.rspeerid_msgto.end(); ++pit) {
		link = RetroShareLink::createMessage(*pit, "");
		if (link.valid())
			text += link.toHtml() + "   ";
	}
	for(std::set<RsGxsId >::const_iterator pit = msgInfo.rsgxsid_msgto.begin(); pit != msgInfo.rsgxsid_msgto.end(); ++pit) {
		link = RetroShareLink::createMessage(*pit, "");
		if (link.valid())
			text += link.toHtml() + "   ";
	}

	ui.toText->setText(text);

    if (!msgInfo.rspeerid_msgcc.empty() || !msgInfo.rsgxsid_msgcc.empty())
    {
		ui.ccLabel->setVisible(true);
		ui.ccText->setVisible(true);

		text.clear();
		for(std::set<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgcc.begin(); pit != msgInfo.rspeerid_msgcc.end(); ++pit) {
			link = RetroShareLink::createMessage(*pit, "");
			if (link.valid())
				text += link.toHtml() + "   ";
		}
		for(std::set<RsGxsId>::const_iterator pit = msgInfo.rsgxsid_msgcc.begin(); pit != msgInfo.rsgxsid_msgcc.end(); ++pit) {
			link = RetroShareLink::createMessage(*pit, "");
			if (link.valid())
				text += link.toHtml() + "   ";
		}

		ui.ccText->setText(text);
	} else {
		ui.ccLabel->setVisible(false);
		ui.ccText->setVisible(false);
		ui.ccText->clear();
	}

	if (!msgInfo.rspeerid_msgbcc.empty() || !msgInfo.rsgxsid_msgbcc.empty())
	{
		ui.bccLabel->setVisible(true);
		ui.bccText->setVisible(true);

		text.clear();
		for(std::set<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgbcc.begin(); pit != msgInfo.rspeerid_msgbcc.end(); ++pit) {
			link = RetroShareLink::createMessage(*pit, "");
			if (link.valid())
				text += link.toHtml() + "   ";
		}
		for(std::set<RsGxsId>::const_iterator pit = msgInfo.rsgxsid_msgbcc.begin(); pit != msgInfo.rsgxsid_msgbcc.end(); ++pit) {
			link = RetroShareLink::createMessage(*pit, "");
			if (link.valid())
				text += link.toHtml() + "   ";
		}

		ui.bccText->setText(text);
	} else {
		ui.bccLabel->setVisible(false);
		ui.bccText->setVisible(false);
		ui.bccText->clear();
	}

	ui.dateText->setText(DateTime::formatDateTime(msgInfo.ts));

    RsPeerId ownId = rsPeers->getOwnId();
	QString tooltip_string ;

//	if ((msgInfo.msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX) // outgoing message are from me
//	{
//		tooltip_string = PeerDefs::rsidFromId(ownId) ;
//		link.createMessage(ownId, "");
//	}

	if(msgInfo.msgflags & RS_MSG_DISTANT)	// distant message
	{
		tooltip_string = PeerDefs::rsidFromId(msgInfo.rsgxsid_srcId) ;
		link = RetroShareLink::createMessage(msgInfo.rsgxsid_srcId, "");
	}
	else
	{
		tooltip_string = PeerDefs::rsidFromId(msgInfo.rspeerid_srcId) ;
		link = RetroShareLink::createMessage(msgInfo.rspeerid_srcId, "");
	}

	if ((msgInfo.msgflags & RS_MSG_SYSTEM) && msgInfo.rspeerid_srcId == ownId) {
		ui.fromText->setText("RetroShare");
		if (toolButtonReply) toolButtonReply->setEnabled(false);
	} else {
		ui.fromText->setText(link.toHtml());
		ui.fromText->setToolTip(tooltip_string) ;
		if (toolButtonReply) toolButtonReply->setEnabled(true);
	}

	ui.subjectText->setText(QString::fromUtf8(msgInfo.title.c_str()));

	// emoticons disabled because of crazy cost.
	//text = RsHtmlMsg(msgInfo.msgflags).formatText(ui.msgText->document(), QString::fromUtf8(msgInfo.msg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
	text = RsHtmlMsg(msgInfo.msgflags).formatText(ui.msgText->document(), QString::fromUtf8(msgInfo.msg.c_str()),  RSHTML_FORMATTEXT_EMBED_LINKS);
	ui.msgText->resetImagesStatus(Settings->getMsgLoadEmbeddedImages() || (msgInfo.msgflags & RS_MSG_LOAD_EMBEDDED_IMAGES));
	ui.msgText->setHtml(text);

	ui.filesText->setText(QString("%1").arg(msgInfo.count));
	ui.filesSize->setText(QString(misc::friendlyUnit(msgInfo.size)));

	showTagLabels();

	currMsgFlags = msgInfo.msgflags;
}
示例#18
0
void Bdecoder::read(QVariant *data)
{
    if (data == NULL) {
        switch (m_buf[m_pos]) {
        case 'd':
            read(static_cast<QVariantMap *>(NULL));
            break;
        case 'l':
            read(static_cast<QVariantList *>(NULL));
            break;
        case 'i':
            read(static_cast<qlonglong *>(NULL));
            break;
        case 'b':
            read(static_cast<bool *>(NULL));
            break;
        case 's':
            read(static_cast<QString *>(NULL));
            break;
        case 'k':
            read(static_cast<BlobKey *>(NULL));
            break;
        default:
            read(static_cast<QByteArray *>(NULL));
            break;
        }
        return;
    }
    switch (m_buf[m_pos]) {
    case 'd': {
            QVariantMap map;
            read(&map);
            *data = map;
        }
        break;
    case 'l': {
            QVariantList list;
            read(&list);
            *data = list;
        }
        break;
    case 'i': {
            /*qlonglong value;
            read(&value);
            if (value >= INT_MIN && value <= INT_MAX)
                *data = int(value);
            else
                *data = value;*/

			qulonglong value;
			bool bSigned = false;
            read(&value, bSigned);
            if (bSigned && qlonglong(value) >= INT_MIN && qlonglong(value) <= INT_MAX)
                *data = int(value);
            else if (qulonglong(value) <= UINT_MAX)
				*data = quint32(value);
			else
                *data = value;
        }
        break;
    case 'b': {
            bool value;
            read(&value);
            *data = value;
        }
        break;
    case 's': {
            QString string;
            read(&string);
            *data = string;
        }
        break;
    case 'k': {
            BlobKey key;
            read(&key);
            *data = QVariant::fromValue(key);
        }
        break;
    default: {
            QByteArray buf;
            read(&buf);
            *data = buf;
        }
        break;
    }
}
bool SingleCellViewSimulationResults::createDataStore()
{
    // Note: the boolean value we return is true if we have had no problem
    //       creating our data store, false otherwise. This is the reason, for
    //       example, we return true when there is either no runtime or if the
    //       simulation size is zero...

    // Delete the previous data store, if any

    deleteDataStore();

    // Make sure that we have a runtime

    if (!mRuntime)
        return true;

    // Retrieve the size of our data and make sure that it is valid

    qulonglong simulationSize = qulonglong(mSimulation->size());

    if (!simulationSize)
        return true;

    // Create our data store and populate it with a variable of integration, as
    // well as with constant, rate, state and algebraic variables

    try {
        mDataStore = new CoreDataStore::CoreDataStore(simulationSize);

        mPoints = mDataStore->addVoi();
        mConstants = mDataStore->addVariables(mRuntime->constantsCount(), mSimulation->data()->constants());
        mRates = mDataStore->addVariables(mRuntime->ratesCount(), mSimulation->data()->rates());
        mStates = mDataStore->addVariables(mRuntime->statesCount(), mSimulation->data()->states());
        mAlgebraic = mDataStore->addVariables(mRuntime->algebraicCount(), mSimulation->data()->algebraic());
    } catch (...) {
        deleteDataStore();

        return false;
    }

    // Customise our variable of integration, as well as our constant, rate,
    // state and algebraic variables

    mPoints->setUri(uri(mRuntime->variableOfIntegration()->componentHierarchy(),
                        mRuntime->variableOfIntegration()->name()));
    mPoints->setLabel(mRuntime->variableOfIntegration()->name());
    mPoints->setUnit(mRuntime->variableOfIntegration()->unit());

    for (int i = 0, iMax = mRuntime->parameters().count(); i < iMax; ++i) {
        CellMLSupport::CellmlFileRuntimeParameter *parameter = mRuntime->parameters()[i];
        CoreDataStore::DataStoreVariable *variable = 0;

        switch (parameter->type()) {
        case CellMLSupport::CellmlFileRuntimeParameter::Constant:
        case CellMLSupport::CellmlFileRuntimeParameter::ComputedConstant:
            variable = mConstants[parameter->index()];

            break;
        case CellMLSupport::CellmlFileRuntimeParameter::Rate:
            variable = mRates[parameter->index()];

            break;
        case CellMLSupport::CellmlFileRuntimeParameter::State:
            variable = mStates[parameter->index()];

            break;
        case CellMLSupport::CellmlFileRuntimeParameter::Algebraic:
            variable = mAlgebraic[parameter->index()];

            break;
        default:
            // Not a type in which we are interested, so do nothing

            ;
        }

        if (variable) {
            variable->setUri(uri(parameter->componentHierarchy(),
                                 parameter->formattedName()));
            variable->setLabel(parameter->formattedName());
            variable->setUnit(parameter->formattedUnit(mRuntime->variableOfIntegration()->unit()));
        }
    }

    return true;
}
示例#20
0
void SpeedGraph::draw(QQueue<QPair<int,int> > data, QSize size, QPaintDevice* device, QPaintEvent* event)
{
	int top = 0;
	QPainter painter(device);
	int seconds = getSettingsValue("graphminutes").toInt()*60;
	bool bFilled = getSettingsValue("graph_style").toInt() == 0;

	painter.setRenderHint(QPainter::Antialiasing);

	if(event != 0)
	{
		painter.setClipRegion(event->region());
		painter.fillRect(event->rect(), QBrush(Qt::white));
	}
	else
		painter.fillRect(QRect(QPoint(0, 0), size), QBrush(Qt::white));

	if(!data.size())
	{
		drawNoData(size, painter);
		return;
	}

	for(int i=0;i<data.size();i++)
	{
		top = qMax(top, qMax(data[i].first,data[i].second));
	}
	if(!top || data.size()<2)
	{
		drawNoData(size, painter);
		return;
	}

	top = qMax(top/10*11,10*1024);

	const int height = size.height();
	const int width = size.width();
	const int elems = data.size();
	qreal perpt = width / (qreal(qMax(elems,seconds))-1);
	qreal pos = width;
	QVector<QLine> lines(elems);
	QVector<QPoint> filler(elems+2);

	for(int i = 0;i<data.size();i++) // download speed
	{
		float y = height-height/qreal(top)*data[elems-i-1].first;
		filler[i] = QPoint(pos, y);
		if(i > 0)
			lines[i-1] = QLine(filler[i-1], filler[i]);
		pos -= perpt;
	}
	filler[elems] = QPoint(filler[elems-1].x(), height);
	filler[elems+1] = QPoint(filler[0].x(), height);
	
	painter.setPen(Qt::darkBlue);
	
	if(bFilled)
	{
		QColor blueFill(Qt::darkBlue);
		blueFill.setAlpha(64);
		painter.setBrush(blueFill);
		painter.drawPolygon(filler.constData(), filler.size(), Qt::OddEvenFill);
	}
	
	lines[elems-1] = QLine(2,7,12,7);
	painter.drawLines(lines.constData(), lines.size());
	
	pos = width;
	for(int i = 0;i<elems;i++) // upload speed
	{
		float y = height-height/qreal(top)*data[elems-i-1].second;
		filler[i] = QPoint(pos, y);
		if(i > 0)
			lines[i-1] = QLine(filler[i-1], filler[i]);
		pos -= perpt;
	}
	filler[elems] = QPoint(filler[elems-1].x(), height);
	filler[elems+1] = QPoint(filler[0].x(), height);
	
	painter.setPen(Qt::darkRed);
	
	if(bFilled)
	{
		QColor redFill(Qt::darkRed);
		redFill.setAlpha(64);
		painter.setBrush(redFill);
		painter.drawPolygon(filler.constData(), filler.size(), Qt::OddEvenFill);
	}
	
	lines[elems-1] = QLine(2,19,12,19);
	painter.drawLines(lines.constData(), lines.size());
	
	painter.setPen(Qt::black);
	for(int i=0;i<4;i++)
	{
		int x = width-(i+1)*(width/4);
		painter.drawLine(x, height, x, height-15);
		painter.drawText(x+2, height-2, tr("%1 mins ago").arg( (seconds/4) * (i+1) / 60.0 ));
	}
	
	painter.drawText(15,12,tr("Download"));
	painter.drawText(15,24,tr("Upload"));
	
	for(int i=1;i<10;i++)
	{
		int pos = int( float(height)/10.f*i );
		
		painter.setPen(QPen(Qt::gray, 1.0, Qt::DashLine));
		painter.drawLine(0,pos,width,pos);
		
		painter.setPen(Qt::black);
		painter.drawText(0,pos-10,formatSize( qulonglong( top/10.f*(10-i) ), true));
	}
}
示例#21
0
/*!
    Writes the object pointed to by \a data with the ID \a type to
    the given \a stream. Returns true if the object is saved
    successfully; otherwise returns false.

    The type must have been registered with qRegisterMetaType() and
    qRegisterMetaTypeStreamOperators() beforehand.

    Normally, you should not need to call this function directly.
    Instead, use QVariant's \c operator<<(), which relies on save()
    to stream custom types.

    \sa load(), qRegisterMetaTypeStreamOperators()
*/
bool QMetaType::save(QDataStream &stream, int type, const void *data)
{
    if (!data || !isRegistered(type))
        return false;

    switch(type) {
    case QMetaType::Void:
    case QMetaType::VoidStar:
    case QMetaType::QObjectStar:
    case QMetaType::QWidgetStar:
        return false;
    case QMetaType::Long:
        stream << qlonglong(*static_cast<const long *>(data));
        break;
    case QMetaType::Int:
        stream << *static_cast<const int *>(data);
        break;
    case QMetaType::Short:
        stream << *static_cast<const short *>(data);
        break;
    case QMetaType::Char:
        // force a char to be signed
        stream << *static_cast<const signed char *>(data);
        break;
    case QMetaType::ULong:
        stream << qulonglong(*static_cast<const ulong *>(data));
        break;
    case QMetaType::UInt:
        stream << *static_cast<const uint *>(data);
        break;
    case QMetaType::LongLong:
        stream << *static_cast<const qlonglong *>(data);
        break;
    case QMetaType::ULongLong:
        stream << *static_cast<const qulonglong *>(data);
        break;
    case QMetaType::UShort:
        stream << *static_cast<const ushort *>(data);
        break;
    case QMetaType::UChar:
        stream << *static_cast<const uchar *>(data);
        break;
    case QMetaType::Bool:
        stream << qint8(*static_cast<const bool *>(data));
        break;
    case QMetaType::Float:
        stream << *static_cast<const float *>(data);
        break;
    case QMetaType::Double:
        stream << *static_cast<const double *>(data);
        break;
    case QMetaType::QChar:
        stream << *static_cast<const ::QChar *>(data);
        break;
#ifndef QT_BOOTSTRAPPED
    case QMetaType::QVariantMap:
        stream << *static_cast<const ::QVariantMap *>(data);
        break;
    case QMetaType::QVariantList:
        stream << *static_cast<const ::QVariantList *>(data);
        break;
#endif
    case QMetaType::QByteArray:
        stream << *static_cast<const ::QByteArray *>(data);
        break;
    case QMetaType::QString:
        stream << *static_cast<const ::QString *>(data);
        break;
    case QMetaType::QStringList:
        stream << *static_cast<const ::QStringList *>(data);
        break;
#ifndef QT_BOOTSTRAPPED
    case QMetaType::QBitArray:
        stream << *static_cast<const ::QBitArray *>(data);
        break;
#endif
    case QMetaType::QDate:
        stream << *static_cast<const ::QDate *>(data);
        break;
    case QMetaType::QTime:
        stream << *static_cast<const ::QTime *>(data);
        break;
    case QMetaType::QDateTime:
        stream << *static_cast<const ::QDateTime *>(data);
        break;
#ifndef QT_BOOTSTRAPPED
    case QMetaType::QUrl:
        stream << *static_cast<const ::QUrl *>(data);
        break;
#endif
    case QMetaType::QLocale:
        stream << *static_cast<const ::QLocale *>(data);
        break;
#ifndef QT_NO_GEOM_VARIANT
    case QMetaType::QRect:
        stream << *static_cast<const ::QRect *>(data);
        break;
    case QMetaType::QRectF:
        stream << *static_cast<const ::QRectF *>(data);
        break;
    case QMetaType::QSize:
        stream << *static_cast<const ::QSize *>(data);
        break;
    case QMetaType::QSizeF:
        stream << *static_cast<const ::QSizeF *>(data);
        break;
    case QMetaType::QLine:
        stream << *static_cast<const ::QLine *>(data);
        break;
    case QMetaType::QLineF:
        stream << *static_cast<const ::QLineF *>(data);
        break;
    case QMetaType::QPoint:
        stream << *static_cast<const ::QPoint *>(data);
        break;
    case QMetaType::QPointF:
        stream << *static_cast<const ::QPointF *>(data);
        break;
#endif
#ifndef QT_NO_REGEXP
    case QMetaType::QRegExp:
        stream << *static_cast<const ::QRegExp *>(data);
        break;
#endif
#ifdef QT3_SUPPORT
    case QMetaType::QColorGroup:
#endif
    case QMetaType::QFont:
    case QMetaType::QPixmap:
    case QMetaType::QBrush:
    case QMetaType::QColor:
    case QMetaType::QPalette:
    case QMetaType::QIcon:
    case QMetaType::QImage:
    case QMetaType::QPolygon:
    case QMetaType::QRegion:
    case QMetaType::QBitmap:
    case QMetaType::QCursor:
    case QMetaType::QSizePolicy:
    case QMetaType::QKeySequence:
    case QMetaType::QPen:
    case QMetaType::QTextLength:
    case QMetaType::QTextFormat:
    case QMetaType::QMatrix:
    case QMetaType::QTransform:
        if (!qMetaTypeGuiHelper)
            return false;
        qMetaTypeGuiHelper[type - FirstGuiType].saveOp(stream, data);
        break;
    default: {
        const QVector<QCustomTypeInfo> * const ct = customTypes();
        if (!ct)
            return false;

        SaveOperator saveOp = 0;
        {
            QReadLocker locker(customTypesLock());
            saveOp = ct->at(type - User).saveOp;
        }

        if (!saveOp)
            return false;
        saveOp(stream, data);
        break; }
    }

    return true;
}
示例#22
0
QString GlobalSearch::PixmapCacheKey(const SearchProvider::Result& result)
    const {
  return "globalsearch:" % QString::number(qulonglong(result.provider_)) % "," %
         result.metadata_.url().toString();
}