怎样在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 ...
随机推荐
- ⒁bootstrap组件 工具提示框 弹出框 警告框 基础案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Problem D: 来开个书店吧
某出版社可出版图书和磁带.其中图书按照每页的价格乘以页数进行定价,磁带根据每10分钟的价格乘以磁带录音的分钟数进行定价.请定义Publicatioin.Book.Tape以及BookStore四个类. ...
- Git Submodules are not SVN Externals
一直在寻找Git跟TFS里面类似SVN Externals的替代方案, 今天终于找到了GIT里面的替代方案,在此做个备注 http://alexking.org/blog/2012/03/05/git ...
- RE : 球体波浪倒计时
背景: 移动端需要做一个倒计时球体水波的效果.主要用到了CSS的SVG瞄点动画和JS的计时器.该动画原型来自于 使用球体水面波动显示进度动画 http://wow.techbrood.com/fid ...
- Spring面试题目
问题清单: 1. 什么是Spring框架?Spring框架有哪些主要模块? 2. 使用Spring框架有什么好处? 3. 什么是控制反转(IOC)?什么是依赖注入? 4. 请解释下Spring中的IO ...
- 主机和VMware中的Linux如实现共享文件夹
当我在网上查了几小时的挂载文件夹方法后发现,VMware中的Linux的挂载和双系统的挂载不同 最终目的就是在/mnt目录下有个hgfs的文件夹 效果图: 首先打开VMware中的Linux系统 具体 ...
- C语 三子棋小游戏
#include <stdio.h> #include <Windows.h> #include<time.h> #define row 3 #define lis ...
- [转]ORACLE递归查询
转自:http://www.oracle.com/technetwork/cn/articles/hartley-recursive-086819-zhs.html 递归数据库处理,也称为材料清单 或 ...
- gulp基础操作实践
按照gulp中文文档对gulp基础操作的一些实践练习,记录以防忘掉. 一,选择并输出文件:gulp.src(globs[,options]) eg:gulp.src('src/less/index.l ...
- 十一、Hadoop学习笔记————数据库与数据仓库
数据仓库是集成的面向主题的数据库的集合 面向主题主要是宏观上解决某一类问题,集合性指数据集 数据库主要处理用于事务处理,数据仓库用于分析处理,数据库适用于操作型数据,便于增删改查, 数据仓库则用于挖掘 ...