怎样在Ubuntu Scope中定义设置变量并读取
在本遍文章中,我们来解说怎么对我们的Ubuntu Scope进行设置。对Scope而言,有些时候我们希望可以使用设置来改变我们的显示。或对我们的搜索进行又一次定义。关于很多其它Scope的开发,请參阅站点:http://developer.ubuntu.com/scopes/
1)首先创建一个最主要的Scope
这样我们就创建了我们的一个最主要的scope了。
2)增加代码来完毕设置功能
com.ubuntu.developer.liu-xiao-guo.settingscope_settingscope-settings.ini
注意这个文件名称和Scope的设置文件
com.ubuntu.developer.liu-xiao-guo.settingscope_settingscope.ini
仅仅有细小的区别。仅仅是在它的后面加上“-settings"就可以。记住千万不要改变这个规则。注意这个文件名称和项目的名称的不同而不同。
configure_file(
"com.ubuntu.developer.liu-xiao-guo.settingscope_settingscope-settings.ini"
"${CMAKE_BINARY_DIR}/src/com.ubuntu.developer.liu-xiao-guo.settingscope_settingscope-settings.ini"
) INSTALL(
FILES "${CMAKE_BINARY_DIR}/src/com.ubuntu.developer.liu-xiao-guo.settingscope_settingscope-settings.ini"
DESTINATION "${SCOPE_INSTALL_DIR}"
)
这样我们的设置文件就能够安装到目标中了。
以下。我们能够对我们的设置文件进行配置。
打开我们的设置文件:
[location]
type = string
defaultValue = London
displayName = Location
[distanceUnit]
type = list
defaultValue = 1
displayName = Distance Unit
displayName[de] = Entfernungseinheit
displayValues = Kilometers;Miles
displayValues[de] = Kilometer;Meilen
[age]
type = number
defaultValue = 23
displayName = Age
[enabled]
type = boolean
defaultValue = true
displayName = Enabled
# Setting without a default value
[color]
type = string
displayName = Color
[limit]
type = number
defaultValue = 20
displayName = 搜寻条数
它被定义为“string”,同一时候它另一个默认的值“London”。
显示的提示为“Location”,当然我们也能够把它改动为“位置”(对中文而言)。
void Query::run(sc::SearchReplyProxy const& reply) { // Read the settings
initScope(); try {
// Start by getting information about the query
const sc::CannedQuery &query(sc::SearchQueryBase::query()); // Trim the query string of whitespace
string query_string = alg::trim_copy(query.query_string()); Client::ResultList results;
if (query_string.empty()) {
// If the string is empty, pick a default
results = client_.search("default");
} else {
// otherwise, use the search string
results = client_.search(query_string);
} // Register a category
auto cat = reply->register_category("results", "Results", "",
sc::CategoryRenderer(CATEGORY_TEMPLATE)); for (const auto &result : results) {
sc::CategorisedResult res(cat); cerr << "it comes here: " << m_limit << endl; // We must have a URI
res.set_uri(result.uri); // res.set_title(result.title);
res.set_title( m_location );
res["subtitle"] = std::to_string(m_limit); // Set the rest of the attributes, art, description, etc
res.set_art(result.art);
res["description"] = result.description; // Push the result
if (!reply->push(res)) {
// If we fail to push, it means the query has been cancelled.
// So don't continue;
return;
}
}
} catch (domain_error &e) {
// Handle exceptions being thrown by the client API
cerr << e.what() << endl;
reply->error(current_exception());
}
} void Query::initScope()
{
unity::scopes::VariantMap config = settings(); // The settings method is provided by the base class
if (config.empty())
cerr << "CONFIG EMPTY!" << endl; m_location = config["location"].get_string(); // Prints "London" unless the user changed the value
cerr << "location: " << m_location << endl; m_limit = config["limit"].get_double();
cerr << "limit: " << m_limit << endl;
}
这里“initScope”在“Run”中被调用。
在InitScope中,我们通过“settings()”来读取设置的值。为了显示的方便,我们在“Run”中,也对读取的值进行简单的显示:
// res.set_title(result.title);
res.set_title( m_location );
res["subtitle"] = std::to_string(m_limit);
我们又一次执行我们的Scope,并能够看到例如以下的图片:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVWJ1bnR1VG91Y2g=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" width="350" height="350" alt="">
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVWJ1bnR1VG91Y2g=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" width="500" height="200" alt="">
怎样在Ubuntu Scope中定义设置变量并读取的更多相关文章
- 【Javascript】: for循环中定义的变量在for循环体外也有效
for循环中定义的变量在for循环体外也有效 <script> (function(){ var a = 111; for(var i=0;i<5;i++){ var carl = ...
- MFC 如何在一个类中使用在其他类中定义的变量或函数
[声明:本文的知识点来源于网络,参考网址:https://blog.csdn.net/bill_ming/article/details/7407848] [以下三种方法亲测有效,可以根据具体情况来选 ...
- ES6 class类中定义私有变量
ES6 class类中定义私有变量 class类的不足 看起来, es6 中 class 的出现拉近了 JS 和传统 OOP 语言的距离.但是,它仅仅是一个语法糖罢了,不能实现传统 OOP 语言一样的 ...
- sql 语句中定义的变量不能和 sql关键字冲突
sql 语句中定义的变量不能和 sql关键字冲突 from bs_email_account account LEFT JOIN bs_group_info gp ON account.group_i ...
- java接口中定义成员变量
//抽象类中可以定义如下成员变量:public abstract class People { public String name; public int age; public abstract ...
- 怎么在Ubuntu Scope中获取location地址信息
Location信息对非常多有地址进行搜索的应用来说非常重要.比方对dianping这种应用来说.我们能够通过地址来获取当前位置的一些信息.在这篇文章中,我们来介绍怎样获取Scope架构中的位置信息. ...
- IT兄弟连 JavaWeb教程 Servlet中定义的变量的作用域类型
在Java语言中,局部变量和实力变量有着不同的作用于,它们的区别如下: 局部变量在一个方法中定义,每当一个线程执行局部变量所在的方法时,在线程的堆栈中就会创建这个局部变量,当线程执行完该方法,局部变量 ...
- shell脚本中定义路径变量出现的BUG
=========================================================================== if 语句中的定义路径变量 引发命令的PATH路 ...
- Objective-c中定义成员变量
ios定义成员变量的方法: 如果只是内部访问,完全可以直接用_xxx(下划线),无需自己定义,编译器会自动生成 如果需要外部访问这个变量,可以用 @property xxx ; @synthesize ...
随机推荐
- 百度Echarts导入
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- mysql 读写分离
常见的读写分离方案:1)Amoeba读写分离2)MySQL-Proxy读写分离3)基于程序读写分离(效率很高,实施难度大,开发改代码) 2)原理 web 访问数据库,通过proxy4040端口作为转发 ...
- Java笔试题解答
1. 下面哪些是Thread类的方法() A start() B run() C exit() D getPriority() 答案:ABD 解析:看Java AP ...
- C#中一些默认的预定义属性
C#中一些默认的预定义属性,见下表: 预定义的属性 有效目标 说明 AttributeUsage Class 指定另一个属性类的有效使用方式 CLSCompliant 全部 指出程序元素是否与CLS兼 ...
- java环境变量和tomcat环境变量配置
一.JAVA环境变量的配置1.首先下载JDK JDK可以在Oracle(甲骨文)公司的官方网站http://www.oracle.com下载2.安装完成后查看JDK安装路径一般是C:\Program ...
- activemq Linux下的编译
1.首先下载源码 ,网址:http://www.apache.org/dyn/closer.lua/activemq/activemq-cpp/3.9.4/activemq-cpp-library-3 ...
- [转载] ZooKeeper原理及使用
转载自http://www.wuzesheng.com/?p=2609 ZooKeeper是Hadoop Ecosystem中非常重要的组件,它的主要功能是为分布式系统提供一致性协调(Coordina ...
- Docker 三剑客之 Compose
Compose 项目是 Docker 官方的开源项目,负责实现对 Docker 容器集群的快速编排,开源地址:https://github.com/docker/compose Compose 中的两 ...
- 为什么大家觉得自学HTML5难?
互联网发展到今天,越来越多的技术岗位人才出现了稀缺的状态,就拿当前的HTML5来讲,基本成为了每家互联网公司不可缺少的人才.如果抓住这个机会,把HTML5搞好,那么前途不可限量,而且这门行业是越老越吃 ...
- 面试相关-转载-well,yzl——持续更新
转载yl,yzl大神的面经,顺便自己复习一下专业课的内容 操作系统相关: 什么是进程, 什么是线程.它们之间的区别和联系. 进程管理内存资源+运行过程, 线程只管理运行过程, 线程要在进程提供的资源基 ...