예제 #1
0
inline void KNMusicTagFfmpeg::setMetadata(AVDictionary *dictionary,
                                          const char *key,
                                          KNMusicDetailInfo &detailInfo,
                                          int tagIndex)
{
    //Get the dictionary entry.
    AVDictionaryEntry *tag = av_dict_get(dictionary, key, NULL, 0);
    //Check the tag pointer.
    if(!tag)
    {
        //Ignore for the NULL tag.
        return;
    }
    //Save the data.
    switch(tagIndex)
    {
    case DiscNumber:
        //Get the disc text.
        setSeparatorData(tag->value, detailInfo, DiscNumber, DiscCount);
        break;
    case TrackNumber:
        //Get the track number.
        setSeparatorData(tag->value, detailInfo, TrackNumber, TrackCount);
        break;
    default:
        //Simply set the value as the data of the text.
        setTextData(detailInfo.textLists[tagIndex],
                    QString(tag->value).simplified());
        break;
    }
}
void CAPresentationHandler::searchOtherSlides(SearchDirection direction) {
    //Reset the count
    d->countMatchesPerSlide = 0;
    if( direction == SearchForward) {
        d->searchSlideNumber = d->currentSlideNum + 1;
    } else if ( direction == SearchBackwards) {
        if( d->currentSlideNum != 0) {
            d->searchSlideNumber = d->currentSlideNum - 1;
        } else {
            return;
        }
    }
    while ((d->searchSlideNumber < totalNumberOfSlides()) && (d->searchSlideNumber >= 0)) {
        setTextData(d->searchSlideNumber);
        setSearchString(d->searchString);
        if(d->matchFound == true) {
            d->currentSlideNum = d->searchSlideNumber;
            setCurrentSlideNumber(d->currentSlideNum);
            setSearchString(d->searchString);
            if(direction == SearchBackwards) {
                d->countMatchesPerSlide = d->findText->matches().count() - 1;
                d->findText->findPrevious();
            }
            break;
        }
        if(direction == SearchForward) {
            d->searchSlideNumber++;
        } else if(direction == SearchBackwards) {
            d->searchSlideNumber--;
        }
    }
}
예제 #3
0
int ServerThread::startServer(const QString &title)
{
	_startmutex.lock();

	start();

	_starter.wait(&_startmutex);
	_startmutex.unlock();

#ifdef HAVE_DNSSD
	// Publish this server via DNS-SD.
	// Note: this code runs in the main thread
	if(_port>0) {
		QSettings cfg;
		if(cfg.value("settings/server/dnssd", true).toBool()) {
			qDebug("Announcing server (port %d) via DNSSD", _port);
			auto dnssd = new KDNSSD::PublicService(
				QString(),
				"_drawpile._tcp",
				_port,
				"local"
			);
			dnssd->setParent(this);

			QMap<QString,QByteArray> txt;
			txt["protocol"] = QStringLiteral(DRAWPILE_PROTO_STR).toUtf8();
			txt["started"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate).toUtf8();
			txt["title"] = title.toUtf8();

			dnssd->setTextData(txt);
			dnssd->publishAsync();
		}
	}
#endif

#ifdef HAVE_UPNP
	if(_port>0) {
		QSettings cfg;
		if(cfg.value("settings/server/upnp", true).toBool()) {
			QString myIp = WhatIsMyIp::localAddress();
			if(WhatIsMyIp::isMyPrivateAddress(myIp)) {
				qDebug() << "UPnP enabled: trying to forward" << _port << "to" << myIp;
				UPnPClient::instance()->activateForward(_port);
				_portForwarded = true;
			}
		}
	}
#endif
	return _port;
}
void CAPresentationHandler::zoomToFit()
{
    updateCanvas();
    setTextData(d->currentSlideNum);
}
예제 #5
0
bool KNMusicTagM4a::parseTag(QFile &musicFile,
                             QDataStream &musicDataStream,
                             KNMusicAnalysisItem &analysisItem)
{
    Q_UNUSED(musicFile)
    //Some comments is from:
    //      http://atomicparsley.sourceforge.net/mpeg-4files.html
    //The m4a file is made of a number of atoms, now they are called 'boxes'.
    //   A box always begins with 4 bytes length and follows 4 bytes name.
    //And first we need to check the header box of the file. Its name is 'ftyp'
    //Check out the data.
    M4ABox ftypBox;
    if(!getBox(musicDataStream, ftypBox, true) ||
            ftypBox.name!="ftyp")
    {
        //This cannot be a m4a file.
        return false;
    }
    //Metadata to be used with iTunes comes in the ilst box inside the moov box.
    //The structure of the ilst is:
    /* moov         <-
     * |-udta
     * | |-meta
     * | | |-ilst
     */
    //We have to keep reading until we find out the moov box.
    M4ABox moovBox;
    while(moovBox.name!="moov")
    {
        //If we cannot find a box, means there's no "moov" box, return false.
        if(!getBox(musicDataStream, moovBox))
        {
            return true;
        }
    }
    //When we comes to here, we should find the "moov" box, expand the box to
    //find out the "udta" box.
    /* moov
     * |-udta       <-
     * | |-meta
     * | | |-ilst
     */
    QList<M4ABox> expandList;
    extractBox(moovBox, expandList);
    //Check the expand list.
    if(expandList.isEmpty())
    {
        return true;
    }
    //Generate a empty box for "udta" box.
    M4ABox udtaBox;
    //Find all the box of the expand list of the "moov" box.
    for(auto i : expandList)
    {
        //Check the name of each box.
        if(i.name=="udta")
        {
            //Save the udta box.
            udtaBox=i;
            //Make the udta box to independent box.
            independent(udtaBox);
            //Clear the moov box.
            clearBox(moovBox);
            break;
        }
    }
    //Check out the data.
    if(udtaBox.name.isEmpty())
    {
        //If the name of the udta box is still empty, means there's no udta box
        //in the moov box, then we are faild to parse.
        return true;
    }
    //Expand the "udta" box, and find "meta" box.
    /* moov
     * |-udta
     * | |-meta     <-
     * | | |-ilst
     */
    expandList.clear();
    extractBox(udtaBox, expandList);
    //Check the expand list.
    if(expandList.isEmpty())
    {
        return true;
    }
    //Generate a empty box for "meta" box.
    M4ABox metaBox;
    //Find all the box of the expand list of the "meta" box.
    for(auto i : expandList)
    {
        //Check the name of each box.
        if(i.name=="meta")
        {
            //Save the udta box.
            metaBox=i;
            //Make the meta box to independent box.
            independent(metaBox);
            //Clear the udta box.
            clearBox(udtaBox);
            break;
        }
    }
    //Check out the box.
    if(metaBox.name.isEmpty())
    {
        //If the name of the meta box is still empty, means we cannot find meta
        //box in the meta box, then we are finished to parse.
        return true;
    }
    //Okay, now we can parse the meta box.
    /* moov
     * |-udta
     * | |-meta
     * | | |-ilst   <-
     */
    //Generate a box for ilst.
    M4ABox ilstBox;
    //Extract the meta box.
    if(!findIlstBox(metaBox, ilstBox))
    {
        //Finished to parse the tag if we cannot file the ilst box.
        return true;
    }
    //Clear the meta box to recover the memory.
    clearBox(metaBox);
    //Okay we are now find out the ilst box. Extract the ilst box and we can now
    //fill our data to the detail info.
    expandList.clear();
    extractBox(ilstBox, expandList);
    //Check out the expand list.
    if(expandList.isEmpty())
    {
        //If there's no data inside the expand list, then our mission is
        //finished.
        return true;
    }
    //Write the expand list to the detail info.
    //Get the detail info.
    KNMusicDetailInfo &detailInfo=analysisItem.detailInfo;
    //Check all box inside the list.
    for(auto i : expandList)
    {
        //Check the name of the box.
        //If it's "covr", means we find out the album art box.
        if(i.name=="covr")
        {
            analysisItem.imageData["M4A"].append(QByteArray(i.data, i.size));
            //Continue to next box.
            continue;
        }
        //Check the index of the box inside the map.
        int atomIndex=m_atomIndexMap.value(i.name, -1);
        //If the atom index is -1, then we have to continue to the next box.
        if(atomIndex==-1)
        {
            continue;
        }
        //Check the data size.
        if(i.size<16)
        {
            continue;
        }
        //Get the data position.
        //Actually there's another box inside the box of the i.
        //We can just skip it to read the data.
        char *dataPosition=i.data+16;
        int dataSize=i.size-16;
        //Output box data to detail info.
        switch(atomIndex)
        {
        case TrackNumber:
            //Ensure the data is enough to set the track number and track count.
            if(dataSize>6)
            {
                //Pick up the third byte data of the position as the track
                //number.
                detailInfo.textLists[TrackNumber]=
                        QString::number(dataPosition[3]);
                //Pick up the fifth byte data of the position as the track
                //count.
                detailInfo.textLists[TrackCount]=
                        QString::number(dataPosition[5]);
            }
            break;
        case DiscNumber:
            //Ensure the data is enough to set the disc number and disc count.
            if(dataSize>6)
            {
                //Pick up the third byte data of the position as the disc
                //number.
                detailInfo.textLists[DiscNumber]=
                        QString::number(dataPosition[3]);
                //Pick up the fifth byte data of the position as the disc
                //count.
                detailInfo.textLists[DiscCount]=
                        QString::number(dataPosition[5]);
            }
            break;
        case Rating:
            if(dataSize>0)
            {
                //Turn the first byte into the rating data.
                detailInfo.textLists[Rating]=
                        QString::number((quint8)dataPosition[0]);
            }
            break;
        default:
            //Check out the data size first.
            if(dataSize>0)
            {
                //Set the whole data as the text data.
                setTextData(detailInfo.textLists[atomIndex],
                            QByteArray(dataPosition, dataSize));
            }
            break;
        }
    }
    return true;
}
예제 #6
0
void ClipboardMonitor::onClipboardChanged(ClipboardMode mode)
{
    QVariantMap data = m_clipboard->data(mode, m_formats);
    auto clipboardData = mode == ClipboardMode::Clipboard
            ? &m_clipboardData : &m_selectionData;

    if ( hasSameData(data, *clipboardData) ) {
        COPYQ_LOG( QString("Ignoring unchanged %1")
                   .arg(mode == ClipboardMode::Clipboard ? "clipboard" : "selection") );
        return;
    }

    *clipboardData = data;

    COPYQ_LOG( QString("%1 changed, owner is \"%2\"")
               .arg(mode == ClipboardMode::Clipboard ? "Clipboard" : "Selection",
                    getTextData(data, mimeOwner)) );

    if (mode != ClipboardMode::Clipboard) {
        const QString modeName = mode == ClipboardMode::Selection
                ? "selection"
                : "find buffer";
        data.insert(mimeClipboardMode, modeName);
    }

    // add window title of clipboard owner
    if ( !data.contains(mimeOwner) && !data.contains(mimeWindowTitle) ) {
        PlatformPtr platform = createPlatformNativeInterface();
        PlatformWindowPtr currentWindow = platform->getCurrentWindow();
        if (currentWindow)
            data.insert( mimeWindowTitle, currentWindow->getTitle().toUtf8() );
    }

#ifdef HAS_MOUSE_SELECTIONS
    if ( (mode == ClipboardMode::Clipboard ? m_clipboardToSelection : m_selectionToClipboard)
        && !data.contains(mimeOwner) )
    {
        const auto text = getTextData(data);
        if ( !text.isEmpty() ) {
            const auto targetData = mode == ClipboardMode::Clipboard
                    ? &m_selectionData : &m_clipboardData;
            const auto targetText = getTextData(*targetData);
            emit synchronizeSelection(mode, text, qHash(targetText));
        }
    }
#endif

    // run automatic commands
    if ( anySessionOwnsClipboardData(data) ) {
        emit clipboardChanged(data, ClipboardOwnership::Own);
    } else if ( isClipboardDataHidden(data) ) {
        emit clipboardChanged(data, ClipboardOwnership::Hidden);
    } else {
        const auto defaultTab = m_clipboardTab.isEmpty() ? defaultClipboardTabName() : m_clipboardTab;
        setTextData(&data, defaultTab, mimeCurrentTab);


#ifdef HAS_MOUSE_SELECTIONS
        if (mode == ClipboardMode::Clipboard ? m_storeClipboard : m_storeSelection) {
#else
        if (m_storeClipboard) {
#endif
            setTextData(&data, m_clipboardTab, mimeOutputTab);
        }

        emit clipboardChanged(data, ClipboardOwnership::Foreign);
    }
}