2013-12-21 16:44:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-12-22 11:35:21 +00:00
|
|
|
|
using System.IO;
|
2013-12-21 16:44:56 +00:00
|
|
|
|
using System.Linq;
|
2013-12-22 11:35:21 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2013-12-21 16:44:56 +00:00
|
|
|
|
using System.Text;
|
2013-12-22 11:35:21 +00:00
|
|
|
|
using System.Windows.Forms;
|
2013-12-21 16:44:56 +00:00
|
|
|
|
|
|
|
|
|
namespace WinAlfred.Plugin.System
|
|
|
|
|
{
|
|
|
|
|
public class Main : IPlugin
|
|
|
|
|
{
|
2013-12-22 11:35:21 +00:00
|
|
|
|
List<Result> availableResults = new List<Result>();
|
|
|
|
|
|
|
|
|
|
[DllImport("user32")]
|
|
|
|
|
public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
|
|
|
|
|
[DllImport("user32")]
|
|
|
|
|
public static extern void LockWorkStation();
|
2013-12-21 16:44:56 +00:00
|
|
|
|
|
|
|
|
|
public List<Result> Query(Query query)
|
|
|
|
|
{
|
2013-12-22 11:35:21 +00:00
|
|
|
|
List<Result> results = new List<Result>();
|
2013-12-21 16:44:56 +00:00
|
|
|
|
if (query.ActionParameters.Count == 0)
|
|
|
|
|
{
|
2013-12-22 11:35:21 +00:00
|
|
|
|
results = availableResults;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
results.AddRange(availableResults.Where(result => result.Title.ToLower().Contains(query.ActionParameters[0].ToLower())));
|
2013-12-21 16:44:56 +00:00
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2013-12-22 11:35:21 +00:00
|
|
|
|
availableResults.Add(new Result
|
|
|
|
|
{
|
|
|
|
|
Title = "Shutdown",
|
|
|
|
|
SubTitle = "Shutdown Computer",
|
|
|
|
|
Score = 100,
|
|
|
|
|
Action = () => MessageBox.Show("shutdown")
|
|
|
|
|
});
|
|
|
|
|
availableResults.Add(new Result
|
|
|
|
|
{
|
|
|
|
|
Title = "Log off",
|
|
|
|
|
SubTitle = "Log off current user",
|
|
|
|
|
Score = 10,
|
|
|
|
|
Action = () => MessageBox.Show("Logoff")
|
|
|
|
|
});
|
|
|
|
|
availableResults.Add(new Result
|
|
|
|
|
{
|
|
|
|
|
Title = "Lock",
|
|
|
|
|
SubTitle = "Lock this computer",
|
|
|
|
|
Score = 20,
|
|
|
|
|
IcoPath = "Images\\lock.png",
|
|
|
|
|
Action = () => LockWorkStation()
|
|
|
|
|
});
|
2013-12-21 16:44:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|