Exemplo n.º 1
0
void ChatImageItem::downloadOrViewImage()
{
    if (retryButton)
    {
        message.status = FMessage::Uploading;
        retryButton = false;
        setButton();

        emit mediaUpload(message);

    } else if (message.media_wa_type == FMessage::Location)
    {
        QString url = (message.media_url.isEmpty())
                ? URL_LOCATION_SHARING +
                    QString::number(message.latitude) + "," +
                    QString::number(message.longitude) + "+(" +
                    message.notify_name.replace("<","&lt;").replace(">","&gt;") + ")"
                : message.media_url;
        QDesktopServices::openUrl(QUrl(url));
    }
    else if (!message.local_file_uri.isEmpty())
    {
        QString uri = "file://" + message.local_file_uri;

        QDBusConnection dbus = QDBusConnection::sessionBus();


        switch (message.media_wa_type)
        {
            case FMessage::Audio:
                if (message.live)
                {
                    AudioPlayer *player = new AudioPlayer(this);

                    connect(player,SIGNAL(progress(int)),this,SLOT(updateTime(int)));
                    connect(player,SIGNAL(finished()),this,SLOT(finishedAudioPlay()));

                    ui->viewImageButton->setEnabled(false);

                    player->play(uri);

                    // We need to notificate the sender that we played the audio
                    emit voiceNotePlayed(message);
                    break;
                }

            case FMessage::Video:
                {
                    DBusNokiaMediaPlayerIf *mediaPlayerBus =
                            new DBusNokiaMediaPlayerIf(NOKIA_MEDIAPLAYER_DBUS_NAME,
                                                       NOKIA_MEDIAPLAYER_DBUS_PATH,
                                                       dbus,this);

                    mediaPlayerBus->mime_open(uri);
                }
                break;

            case FMessage::Image:
                {
                    // The following is to avoid an Image Viewer bug where files without
                    // EXIF data can't be opened.

                    QImageReader image(message.local_file_uri);

                    if (image.format() == "jpeg")
                    {
                        ExifData *ed = exif_data_new_from_file(message.local_file_uri.toUtf8().constData());

                        if (!ed)
                        {
                            ed = exif_data_new();
                            if (ed)
                            {
                                Utilities::logData("Creating default Exif data.");
                                ExifEntry *entry = exif_entry_new();

                                exif_content_add_entry(ed->ifd[EXIF_IFD_0], entry);

                                exif_entry_initialize(entry, EXIF_TAG_IMAGE_DESCRIPTION);
                                entry->data = (unsigned char *) YAPPARI_APPLICATION_NAME;

                                JPEGData *jpeg = jpeg_data_new_from_file(message.local_file_uri.toUtf8().constData());

                                jpeg_data_set_exif_data(jpeg, ed);

                                jpeg_data_save_file(jpeg, message.local_file_uri.toUtf8().constData());
                                jpeg_data_unref(jpeg);
                            }
                        }

                        if (ed)
                            exif_data_unref(ed);
                    }

                    DBusNokiaImageViewerIf *imageViewerBus =
                    new DBusNokiaImageViewerIf(NOKIA_IMAGEVIEWER_DBUS_NAME,
                                               NOKIA_IMAGEVIEWER_DBUS_PATH,
                                               dbus,this);

                    imageViewerBus->mime_open(uri);
                }
                break;
        }
Exemplo n.º 2
0
ChatWindow *MainWindow::createChatWindow(Contact& contact, bool show)
{
    // Just open one window at a time to avoid duplicates
    createWindowMutex.lock();

    ChatWindow *chat;

    QString jid = contact.jid;

    if (contact.type == Contact::TypeGroup)
        Utilities::logData("Group");
    else
        Utilities::logData("Contact");

    if (!chatWindowList.contains(jid))
    {
        Utilities::logData("There's no previous chat window");

        if (contact.type == Contact::TypeContact)
            chat = new ChatWindow(&contact,this);
        else
            chat = new GroupWindow((Group *)&contact,this);

        chatWindowList.insert(jid,chat);

        if (!lastContactsList.contains(jid))
        {
            // This is a new chat and it is not in the
            // open chats list

            // Create the open chats item
            ChatDisplayItem *item = new ChatDisplayItem(&contact);
            lastContactsList.insert(jid,item);
            model->appendRow(item);

            // Set the last line logged in the item
            FMessage msg = chat->lastMessage();
            item->updateData(msg);

            // Store this chat in the DB
            ConversationsDBEntry entry;
            entry.jid = jid;
            entry.muted = false;
            entry.muteExpireTimestamp = 0;
            chatsDB.createChat(entry);

            if (contact.type == Contact::TypeContact)
                emit subscribe(jid);
        }
        else
        {
            // This chat is in the open chats list

            // Configure mute settings
            ChatDisplayItem *item = lastContactsList.value(jid);
            if (item->muted)
                chat->setMute(item->muteExpireTimestamp);
        }

        chat->setAttribute(Qt::WA_DeleteOnClose);

        if (!show)
                Utilities::logData("Chat window will not be shown");
        if (show)
        {
            Utilities::logData("Showing chat window");
            qint64 startTime = QDateTime::currentMSecsSinceEpoch();
            chat->show();
            qint64 endTime = QDateTime::currentMSecsSinceEpoch() - startTime;
            Utilities::logData("Chat window showed " + QString::number(endTime) +
                               " milliseconds.");
        }

        connect(chat,SIGNAL(sendMessage(FMessage)),
                this,SLOT(sendMessageFromChat(FMessage)));

        connect(chat,SIGNAL(destroyed(QObject *)),
                this,SLOT(deleteChat(QObject *)));

        connect(chat,SIGNAL(mute(QString,bool,qint64)),
                this,SLOT(mute(QString,bool,qint64)));

        connect(chat,SIGNAL(blockOrUnblockContact(QString,bool)),
                this,SLOT(blockOrUnblockContact(QString,bool)));

        connect(chat,SIGNAL(photoRefresh(QString,QString,bool)),
                this,SLOT(requestPhotoRefresh(QString,QString,bool)));

        connect(chat,SIGNAL(requestStatus(QString)),
                this,SLOT(requestContactStatus(QString)));

        connect(chat,SIGNAL(voiceNotePlayed(FMessage)),
                this,SLOT(sendVoiceNotePlayed(FMessage)));

        if (contact.type == Contact::TypeGroup)
        {
            GroupWindow *groupChat = (GroupWindow *) chat;
            connect(groupChat,SIGNAL(changeSubject(QString,QString)),
                    this,SLOT(sendSetGroupSubjectFromChat(QString,QString)));

            connect(groupChat,SIGNAL(requestLeaveGroup(QString)),
                    this,SLOT(requestLeaveGroupFromChat(QString)));

            connect(groupChat,SIGNAL(getParticipants(QString)),
                    this,SLOT(requestGetParticipants(QString)));
        }
        else
            emit queryLastOnline(jid);
    }