Exemple #1
0
	void Plugin::handleFinished ()
	{
		auto proc = qobject_cast<QProcess*> (sender ());
		proc->deleteLater ();

		const auto entryObj = Process2Entry_.take (proc);
		if (!entryObj)
		{
			qWarning () << Q_FUNC_INFO
					<< "no entry for process"
					<< proc;
			return;
		}
#ifdef Q_OS_WIN32
		auto out = QString::fromUtf16 (reinterpret_cast<const ushort*> (proc->readAllStandardOutput ().constData ()));
#else
		auto out = QString::fromUtf8 (proc->readAllStandardOutput ());
#endif
		const auto& err = proc->readAllStandardError ();

		if (!err.isEmpty ())
#ifdef Q_OS_WIN32
			out.prepend (tr ("Error: %1").arg (QString::fromUtf16 (reinterpret_cast<const ushort*> (err.constData ()))) + "\n");
#else
			out.prepend (tr ("Error: %1").arg (QString::fromUtf8 (err)) + "\n");
#endif

		const auto entry = qobject_cast<ICLEntry*> (entryObj);
		AzothProxy_->OpenChat (entry->GetEntryID (),
				entry->GetParentAccount ()->GetAccountID (),
				out);
	}
	void BookmarksManagerDialog::SuggestSaving (QObject *entryObj)
	{
		const auto entry = qobject_cast<ICLEntry*> (entryObj);
		if (!entry)
		{
			qWarning () << Q_FUNC_INFO
					<< "object doesn't implement ICLEntry"
					<< entryObj;
			return;
		}

		const bool found = FocusOn (entry->GetParentAccount ());

		if (!found)
		{
			qWarning () << Q_FUNC_INFO
					<< "unable to find parent protocol for entry"
					<< entryObj
					<< entry->GetEntryID ();
			return;
		}

		const auto& data = GetIdentifyingData (entryObj);
		if (data.isEmpty ())
		{
			qWarning () << Q_FUNC_INFO
					<< "empty identifying data returned by"
					<< entryObj;
			return;
		}

		AddBookmark (data);
	}
Exemple #3
0
DWORD  WINAPI CAutorunHandle::GetEntryType()                 ///< [所有启动项] 获取启动项类型ID
{
    if ( FALSE == CheckOperateData() )
    {
        return E_FAIL;
    }
	return CAutorunItem::GetEntryTypeByID( GetEntryID() );
}
Exemple #4
0
	void EntryBase::SetAvatar (const QImage& avatar)
	{
		Avatar_ = avatar;

		const auto id = GetEntryID ().toUtf8 ().toHex ();
		Core::Instance ().GetAvatarsStorage ()->StoreAvatar (Avatar_, id);

		emit avatarChanged (Avatar_);
	}
Exemple #5
0
	void Plugin::hookTooltipBeforeVariants (IHookProxy_ptr proxy, QObject *entryObj)
	{
		if (!IsGoodEntry (entryObj))
			return;

		const auto entry = qobject_cast<ICLEntry*> (entryObj);
		const auto& id = entry->GetEntryID ();

		const auto& maybeStats = Storage_->GetEntryStats (id);
		if (!maybeStats)
			return;

		const auto& stats = *maybeStats;

		QString addition;

		const auto curState = entry->GetStatus ().State_;

		if (curState != SOnline)
		{
			const auto& avail = stats.Available_;
			if (avail.isValid ())
				addition += tr ("Was available: %1")
					.arg (avail.toString ());
		}

		if (curState == SOffline ||
				curState == SError ||
				curState == SInvalid)
		{
			const auto& online = stats.Online_;
			if (online.isValid ())
			{
				if (!addition.isEmpty ())
					addition += "<br/>";
				addition += tr ("Was online: %1")
					.arg (online.toString ());
			}
		}

		const auto& lastChange = stats.StatusChange_;
		if (lastChange.isValid ())
		{
			if (!addition.isEmpty ())
				addition += "<br/>";
			addition += tr ("Last status change: %1")
					.arg (lastChange.toString ());
		}

		if (addition.isEmpty ())
			return;

		const auto& tip = proxy->GetValue ("tooltip").toString ();
		proxy->SetValue ("tooltip", tip + "<br/><br/>" + addition + "<br/>");
	}
Exemple #6
0
	void Plugin::hookEntryStatusChanged (IHookProxy_ptr, QObject *entryObj, QString variant)
	{
		if (!IsGoodEntry (entryObj))
			return;

		if (variant.isEmpty ())
			return;

		const auto entry = qobject_cast<ICLEntry*> (entryObj);
		const auto& id = entry->GetEntryID ();
		const auto& status = entry->GetStatus ();

		if (!LastState_.contains (id))
		{
			LastState_ [id] = status.State_;
			return;
		}

		const State oldState = LastState_ [id];
		if (oldState == status.State_)
			return;

		LastState_ [id] = status.State_;

		const auto& now = QDateTime::currentDateTime ();

		auto stats = Storage_->GetEntryStats (id).get_value_or ({});
		stats.StatusChange_ = now;

		switch (oldState)
		{
		case SOffline:
		case SProbe:
		case SError:
		case SInvalid:
		case SConnecting:
			return;
		case SOnline:
			stats.Available_ = now;
		default:
			stats.Online_ = now;
			break;
		}

		auto st = Storage_;
		Util::ExecuteLater ([stats, st, id] { st->SetEntryStats (id, stats); });
	}
Exemple #7
0
/**
 * @brief	Gets NPC information for use in various NPC packets.
 *
 * @param	pkt	The packet the information will be stored in.
 */
void CNpc::GetNpcInfo(Packet & pkt)
{
	pkt << GetEntryID()
		<< uint8(isMonster() ? 1 : 2) // Monster = 1, NPC = 2 (need to use a better flag)
		<< m_sPid
		<< GetType()
		<< m_iSellingGroup
		<< m_sSize
		<< m_iWeapon_1 << m_iWeapon_2
		// Monsters require 0 regardless, otherwise they'll act as NPCs.
		<< uint8(isMonster() ? 0 : GetNation())
		<< GetLevel()
		<< GetSPosX() << GetSPosZ() << GetSPosY()
		<< uint32(isGateOpen())
		<< m_byObjectType
		<< uint16(0) << uint16(0) // unknown
		<< int16(m_byDirection);
}
	void FileTransferManager::handleRequest (int32_t friendNum,
			const QByteArray& pkey, uint8_t filenum, uint64_t size, const QString& name)
	{
		const auto toxThread = ToxThread_.lock ();
		if (!toxThread)
		{
			qWarning () << Q_FUNC_INFO
					<< "Tox thread is not available";
			return;
		}

		const auto entry = Acc_->GetByPubkey (pkey);
		if (!entry)
		{
			qWarning () << Q_FUNC_INFO
					<< "unable to find entry for pubkey"
					<< pkey;
			return;
		}

		const auto transfer = new FileTransferIn
		{
			entry->GetEntryID (),
			pkey,
			friendNum,
			filenum,
			static_cast<qint64> (size),
			name,
			toxThread
		};

		connect (this,
				SIGNAL (gotFileControl (qint32, qint8, qint8, QByteArray)),
				transfer,
				SLOT (handleFileControl (qint32, qint8, qint8, QByteArray)));
		connect (this,
				SIGNAL (gotData (qint32, qint8, QByteArray)),
				transfer,
				SLOT (handleData (qint32, qint8, QByteArray)));

		emit fileOffered (transfer);
	}
	void NotificationsManager::handleClearUnreadMsgCount (QObject *entryObj)
	{
		const auto entry = qobject_cast<ICLEntry*> (entryObj);
		UnreadCounts_.remove (entry);

		const auto& entryID = entry->GetEntryID ();

		auto e = Util::MakeNotification ("Azoth", {}, PInfo_);
		e.Additional_ ["org.LC.AdvNotifications.SenderID"] = "org.LeechCraft.Azoth";
		e.Additional_ ["org.LC.AdvNotifications.EventID"] =
				"org.LC.Plugins.Azoth.IncomingMessageFrom/" + entryID;
		e.Additional_ ["org.LC.AdvNotifications.EventCategory"] = "org.LC.AdvNotifications.Cancel";

		EntityMgr_->HandleEntity (e);

		e.Additional_ ["org.LC.AdvNotifications.EventID"] =
				"org.LC.Plugins.Azoth.AttentionDrawnBy/" + entryID;

		EntityMgr_->HandleEntity (e);
	}
Exemple #10
0
/**
 * @brief	Executes the death action.
 *
 * @param	pKiller	The killer.
 */
void CNpc::OnDeath(Unit *pKiller)
{
	if (m_NpcState == NPC_DEAD)
		return;

	ASSERT(GetMap() != nullptr);
	ASSERT(GetRegion() != nullptr);

	m_NpcState = NPC_DEAD;

	if (m_byObjectType == SPECIAL_OBJECT)
	{
		_OBJECT_EVENT *pEvent = GetMap()->GetObjectEvent(GetEntryID());
		if (pEvent != nullptr)
			pEvent->byLife = 0;
	}

	Unit::OnDeath(pKiller);

	GetRegion()->Remove(TO_NPC(this));
	SetRegion();
}
	void PasteServiceBase::FeedURL (const QString& pasteUrl)
	{
		if (!Entry_)
		{
			QApplication::clipboard ()->setText (pasteUrl, QClipboard::Clipboard);
			QApplication::clipboard ()->setText (pasteUrl, QClipboard::Selection);

			const Entity& e = Util::MakeNotification (tr ("Text pasted"),
					tr ("Your text has been pasted: %1. The URL has "
						"been copied to the clipboard."),
					PInfo_);
			Proxy_->GetEntityManager ()->HandleEntity (e);

			return;
		}

		auto entry = qobject_cast<ICLEntry*> (Entry_);
		if (!entry)
		{
			qWarning () << Q_FUNC_INFO
					<< "unable to cast"
					<< Entry_
					<< "to ICLEntry";
			return;
		}

		auto type = entry->GetEntryType () == ICLEntry::EntryType::MUC ?
				IMessage::Type::MUCMessage :
				IMessage::Type::ChatMessage;
		const auto msg = entry->CreateMessage (type, QString (), pasteUrl);
		if (!msg)
		{
			qWarning () << Q_FUNC_INFO
					<< "unable to create message for"
					<< entry->GetEntryID ();
			return;
		}
		msg->Send ();
	}
	void NotificationsManager::HandleMessage (IMessage *msg)
	{
		const bool showMsg = XmlSettingsManager::Instance ()
				.property ("ShowMsgInNotifications").toBool ();

		const auto other = qobject_cast<ICLEntry*> (msg->OtherPart ());
		const auto parentCL = qobject_cast<ICLEntry*> (msg->ParentCLEntry ());

		QString msgString;
		bool isHighlightMsg = false;
		switch (msg->GetMessageType ())
		{
		case IMessage::Type::ChatMessage:
			if (XmlSettingsManager::Instance ()
					.property ("NotifyAboutIncomingMessages").toBool ())
			{
				if (!showMsg)
					msgString = tr ("Incoming chat message from <em>%1</em>.")
							.arg (other->GetEntryName ());
				else
				{
					const auto& body = msg->GetEscapedBody ();
					const auto& notifMsg = body.size () > 50 ?
							body.left (50) + "..." :
							body;
					msgString = tr ("Incoming chat message from <em>%1</em>: <em>%2</em>")
							.arg (other->GetEntryName ())
							.arg (notifMsg);
				}
			}
			break;
		case IMessage::Type::MUCMessage:
		{
			isHighlightMsg = Core::Instance ().IsHighlightMessage (msg);
			if (isHighlightMsg && XmlSettingsManager::Instance ()
					.property ("NotifyAboutConferenceHighlights").toBool ())
			{
				if (!showMsg)
					msgString = tr ("Highlighted in conference <em>%1</em> by <em>%2</em>.")
							.arg (parentCL->GetEntryName ())
							.arg (other->GetEntryName ());
				else
				{
					const auto& body = msg->GetEscapedBody ();
					const auto& notifMsg = body.size () > 50 ?
							body.left (50) + "..." :
							body;
					msgString = tr ("Highlighted in conference <em>%1</em> by <em>%2</em>: <em>%3</em>")
							.arg (parentCL->GetEntryName ())
							.arg (other->GetEntryName ())
							.arg (notifMsg);
				}
			}
			break;
		}
		default:
			return;
		}

		auto e = Util::MakeNotification ("Azoth",
				msgString,
				PInfo_);

		if (msgString.isEmpty ())
			e.Mime_ += "+advanced";

		auto entry = msg->GetMessageType () == IMessage::Type::MUCMessage ?
				parentCL :
				other;
		BuildNotification (e, entry);

		const auto count = ++UnreadCounts_ [entry];
		if (msg->GetMessageType () == IMessage::Type::MUCMessage)
		{
			e.Additional_ ["org.LC.Plugins.Azoth.SubSourceID"] = other->GetEntryID ();
			e.Additional_ ["org.LC.AdvNotifications.EventType"] = isHighlightMsg ?
					AN::TypeIMMUCHighlight :
					AN::TypeIMMUCMsg;
			e.Additional_ ["NotificationPixmap"] = QVariant::fromValue (other->GetAvatar ());

			if (isHighlightMsg)
				e.Additional_ ["org.LC.AdvNotifications.FullText"] =
					tr ("%n message(s) from", 0, count) + ' ' + other->GetEntryName () +
							" <em>(" + parentCL->GetEntryName () + ")</em>";
			else
				e.Additional_ ["org.LC.AdvNotifications.FullText"] =
					tr ("%n message(s) in", 0, count) + ' ' + parentCL->GetEntryName ();
		}
		else
		{
			e.Additional_ ["org.LC.AdvNotifications.EventType"] = AN::TypeIMIncMsg;
			e.Additional_ ["org.LC.AdvNotifications.FullText"] =
				tr ("%n message(s) from", 0, count) +
						' ' + other->GetEntryName ();
		}

		e.Additional_ ["org.LC.AdvNotifications.Count"] = count;

		e.Additional_ ["org.LC.AdvNotifications.ExtendedText"] = tr ("%n message(s)", 0, count);
		e.Additional_ ["org.LC.Plugins.Azoth.Msg"] = msg->GetEscapedBody ();

		const auto nh = new Util::NotificationActionHandler { e, this };
		nh->AddFunction (tr ("Open chat"),
				[parentCL] { Core::Instance ().GetChatTabsManager ()->OpenChat (parentCL, true); });
		nh->AddDependentObject (parentCL->GetQObject ());

		EntityMgr_->HandleEntity (e);
	}