Simple AppIndicator with Vala application under Elementary OS - panel

Yesterday I've been stuck on some hard things. Something that looks simple at first but who's not thrust me :/
Here is what i'm trying to have : An appindicator (statusicon ?) with a custom icon for my application.
Unfortunately, there is nothing I found inside valadoc, except this but it's deprecated and it says we should use Notifications which is really not the same thing
I've heard about .vapi Appindicator files, but this is no real documentation about how to use it
If someone can post code about integrating AppIndicator inside vala code, I would be thankful !
Thanks

Have you tried the Vala example included in libappindicator?
http://bazaar.launchpad.net/~indicator-applet-developers/libappindicator/trunk.15.10/view/head:/bindings/vala/examples/indicator-example.vala
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Marco Trevisan (Treviño) <mail#3v1n0.net>
*/
using Gtk;
using AppIndicator;
public class IndicatorExample {
public static int main(string[] args) {
Gtk.init(ref args);
var win = new Window();
win.title = "Indicator Test";
win.resize(200, 200);
win.destroy.connect(Gtk.main_quit);
var label = new Label("Hello, world!");
win.add(label);
var indicator = new Indicator(win.title, "indicator-messages",
IndicatorCategory.APPLICATION_STATUS);
if (!(indicator is Indicator)) return -1;
indicator.set_status(IndicatorStatus.ACTIVE);
indicator.set_attention_icon("indicator-messages-new");
var menu = new Gtk.Menu();
var item = new Gtk.MenuItem.with_label("Foo");
item.activate.connect(() => {
indicator.set_status(IndicatorStatus.ATTENTION);
});
item.show();
menu.append(item);
var bar = item = new Gtk.MenuItem.with_label("Bar");
item.show();
item.activate.connect(() => {
indicator.set_status(IndicatorStatus.ACTIVE);
});
menu.append(item);
indicator.set_menu(menu);
indicator.set_secondary_activate_target(bar);
win.show_all();
Gtk.main();
return 0;
}
}

Related

Could not find iPhone 6(or any other) simulator React-Native, nothing helps?

Can not run my project with iOS simulator
ISSUE,
Could not find iPhone 6(or X or any other) simulator
XCODE: 10.2
react-native: 0.52
react: ^16.0.0-alpha.12
Here is my findMatchingSimulator.js from nodemodules/react-native/local-cli/runIOS:
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.*
*/
'use strict';
/**
* Takes in a parsed simulator list and the desired name, and returns an object with the matching simulator.
*
* If the simulatorName argument is null, we'll go into default mode and return the currently booted simulator, or if
* none is booted, it will be the first in the list.
*
* #param Object simulators a parsed list from `xcrun simctl list --json devices` command
* #param String|null simulatorName the string with the name of desired simulator. If null, it will use the currently
* booted simulator, or if none are booted, the first in the list.
* #returns {Object} {udid, name, version}
*/
function findMatchingSimulator(simulators, simulatorName) {
if (!simulators.devices) {
return null;
}
const devices = simulators.devices;
var match;
for (let version in devices) {
// Making sure the version of the simulator is an iOS (Removes Apple Watch, etc)
if (version.indexOf('iOS') !== 0) {
continue;
}
for (let i in devices[version]) {
let simulator = devices[version][i];
// Skipping non-available simulator
if (simulator.availability !== '(available)') {
continue;
}
// If there is a booted simulator, we'll use that as instruments will not boot a second simulator
if (simulator.state === 'Booted') {
if (simulatorName !== null) {
console.warn("We couldn't boot your defined simulator due to an already booted simulator. We are limited to one simulator launched at a time.");
}
return {
udid: simulator.udid,
name: simulator.name,
version
};
}
if (simulator.name === simulatorName && !match) {
match = {
udid: simulator.udid,
name: simulator.name,
version
};
}
// Keeps track of the first available simulator for use if we can't find one above.
if (simulatorName === null && !match) {
match = {
udid: simulator.udid,
name: simulator.name,
version
};
}
}
}
if (match) {
return match;
}
return null;
}
module.exports = findMatchingSimulator;
I tried different methods, but nothing helps.
The list of available devices specifies iPhones as “unavailable”
Change this line:
if (version.indexOf('iOS') !== 0) {
to this:
if (version.indexOf('com.apple.CoreSimulator.SimRuntime.iOS') !== 0) {
There was a recent change to xcode, and the simulator names are now prefixed. This solved it for me.

Custom HttpContent won't build - Could not AOT the assembly (mtouch)

In my efforts to create a progress indicator for uploading videos using HttpClient (SendAsync) in Xamarin Forms, I now have to ask for assistance.
The upload itself works fine, and all other API calls, but when I try to create a custom HttpContent to track the progress of the upload the project won't even build any more.
Error MT3001: Could not AOT the assembly
'[...].iOS/obj/iPhone/Debug/build-iphone7.2-10.1.1/mtouch-cache/Build/theproject.dll'
(MT3001) (theproject.iOS)
Using StreamContent or ByteArrayContent instead the project builds, but I can't get it working to track the progress.
A snippet of code (this is minimal example):
public class ProgressableContent : HttpContent
{
private const int defaultBufferSize = 4096;
private Stream content;
private int progress;
public ProgressableContent(Stream content)
{
this.content = content;
}
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
return Task.Run(async () =>
{
var buffer = new byte[defaultBufferSize];
var size = content.Length;
var uploaded = 0;
using (content) while (true)
{
var length = content.Read(buffer, 0, buffer.Length);
if (length <= 0) break;
uploaded += length;
progress = (int)((float)uploaded / size * 100);
await stream.WriteAsync(buffer, 0, length);
}
});
}
protected override bool TryComputeLength(out long length)
{
length = content.Length;
return true;
}
}
I use this by transforming my byte's to a stream, hopefully correctly:
//... building httpMessage.
httpMessage.Content = new ProgressableContent(await byteArrayContent.ReadAsStreamAsync());
//...
var response = await _httpClient.SendAsync(httpMessage, Cancellation.Token);
//...
The question(s):
Am I somehow causing the error? Is there a "better" way to do this?
Tagged this with Xamarin.iOS also since monotouch is complaining.
Double-click on the error from XS and it should bring you to a web page that provide more description about the issue. E.g.
MT3001 Could not AOT the assembly '*'
This generally indicates a bug in the AOT compiler. Please file a bug
http://bugzilla.xamarin.com with a project that can be used to
reproduce the error.
Sometimes it's possible to work around this by disabling incremental
builds in the project's iOS Build option (but it's still a bug, so
please report it anyways).
The main thing about 3001 is that the AOT compiler did not produce an output binary. There can be several reasons for this. Generally the process crashed and the build logs will give a bit more details why.
Even more important is to attach a self-contained test case to the bug report. Something else, beside the code you pasted, can be playing an important part that led to the crash (and it could be impossible to duplicate or guess what that piece could be). That also gives us a better chance to suggest a workaround to the issue.

Create java-like document for function in IOS (Xcode)

I'm beginner with IOS developing and I'm using Xcode. In java (android), I can create document for a function like below:
/**
* Get the index object in list of object and try to catch
* {#link IndexOutOfBoundsException}
*
* #param list
* of object: {#link List}
* #param index
* of ojbect: {#link Integer}
* #return Object or null if {#link IndexOutOfBoundsException} occurs
*/
public static <T> T getIndexObject(List<T> list, int index) {
T object = null;
try {
object = list.get(index);
} catch (IndexOutOfBoundsException e) {
return null;
}
return object;
}
When I create document as above (in Java), every time when I hover the mouse over the function (used in every where), I will see the document of that function. How's about IOS in Xcode? I know Doxygen, but It only generate HTML files (that not what I want). I want document like default document of every function that provided by Apple (when Ctrl + click on a function of IOS SDK)? Can I do it? And how? Thanks!!
Use AppleDoc. They have an article on their site that explains how to integrate with Xcode: http://gentlebytes.com/appledoc-docs-examples-xcode/, basically, you use:
appledoc
--project-name appledoc
--project-company "Gentle Bytes"
--company-id com.gentlebytes
--output ~/help
--logformat xcode
.
to generate the documents. You can also do the normal HTML in addition. It's free and looks a lot like Apple's documentation.

Error with undefined method CI_Loader::plugin()

I received the following error:
Call to undefined method CI_Loader::plugin() in C:\wamp\www\Code\application\libraries\DX_Auth.php on line 1233
on this code:
function captcha()
{
$this->ci->load->helper('url');
$this->ci->load->plugin('dx_captcha');
$captcha_dir = trim($this->ci->config->item('DX_captcha_path'), './');
Make sure you have moved any array values in application/config/autoload.php from $autoload[‘plugins’] to $autoload[‘helpers’] or you will notice stuff break.
This is the reference
Which version of CI are you using? Plugins has been removed since the 2.x and replaced with helper.
Try to use reCaptcha instead, it has a good library.
You're trying to load a plugin and plugins are not supported, if I remember it right since CI version 2. If that's the case (which seems to be) you need to convert your plugins into helpers.
I think you are trying to use an old version of DX_Auth on new version of CodeIgniter. Current version of DX_Auth is compatible with CI 2.x and is available on github.
A simple way to solve this problem is that you just put this code in your loader.php. The plugin its works. Go to System->Core->Loader.php.
/**
* Load Plugin
*
* This function loads the specified plugin.
*
* #access public
* #param array
* #return void
*/
function plugin($plugins = array())
{
if ( ! is_array($plugins))
{
$plugins = array($plugins);
}
foreach ($plugins as $plugin)
{
$plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi');
if (isset($this->_ci_plugins[$plugin]))
{
continue;
}
if (file_exists(APPPATH.'plugins/'.$plugin.EXT))
{
include_once(APPPATH.'plugins/'.$plugin.EXT);
}
else
{
if (file_exists(BASEPATH.'plugins/'.$plugin.EXT))
{
include_once(BASEPATH.'plugins/'.$plugin.EXT);
}
else
{
show_error('Unable to load the requested file: plugins/'.$plugin.EXT);
}
}
$this->_ci_plugins[$plugin] = TRUE;
log_message('debug', 'Plugin loaded: '.$plugin);
}
}
// --------------------------------------------------------------------
/**
* Load Plugins
*
* This is simply an alias to the above function in case the
* user has written the plural form of this function.
*
* #access public
* #param array
* #return void
*/
function plugins($plugins = array())
{
$this->plugin($plugins);
}

Getting mount point when a USB device is inserted Mac OS X and linux

I am trying to develop a program in Mac OS and Linux which lists the files and folders in USB drive. I need to get the some events when USB device is connected and removed. I know that in Mac OS X I can use IOKit. But I do n't know how to get the mount point where the device is mounted. Can I get it using IOkit? Is there any cross platform solution for Linux and Mac?
No, there isn't. Under Linux you may use HAL or DeviceKit-disks D-Bus interfaces. Note those are optional components and may be absent. HAL is older and DeviceKit-disks is newer implementations, with DK-d replacing HAL.
The approach I used for getting the available mount-points (with Java) pipes the output of the "system_profiler SPUSBDataType -xml" command to dd-plist processor. It subsequently recurses over the USB hierarchy, matching those having a "volumes" key. For each item in this array, retrieve the "mount_point" key to retrieve the location where it is mounted. See the code sample below:
/*
Copyright © 2014 Edwin de Jong. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY [LICENSOR] "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package nl.topicuszorg.laos.util.osx;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import nl.topicuszorg.laos.model.response.MountState;
import nl.topicuszorg.laos.model.response.MountedDevice;
import org.xml.sax.SAXException;
import com.dd.plist.NSArray;
import com.dd.plist.NSDictionary;
import com.dd.plist.NSObject;
import com.dd.plist.NSString;
import com.dd.plist.PropertyListFormatException;
import com.dd.plist.PropertyListParser;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
public class USBHelpers
{
private static final String SYSTEM_PROFILER_COMMAND = "/usr/sbin/system_profiler";
private static final String SPUSB_DATA_TYPE = "SPUSBDataType";
private interface SpUSBDataTypeIdentifiers
{
String ITEMS = "_items";
String VOLUMES = "volumes";
String VENDOR_ID = "vendor_id";
String MOUNT_POINT = "mount_point";
String NAME = "_name";
}
public static List<MountedDevice> findMountedDevicesOsX() throws IOException, PropertyListFormatException,
ParseException, ParserConfigurationException, SAXException
{
final Process process = new ProcessBuilder(SYSTEM_PROFILER_COMMAND, SPUSB_DATA_TYPE, "-xml")
.start();
return findMountedDevicesInConfiguration(process.getInputStream());
}
private static List<MountedDevice> findMountedDevicesInConfiguration(final InputStream processInputStream)
throws IOException, PropertyListFormatException, ParseException, ParserConfigurationException, SAXException
{
// Root is an array, the USB devices are hierarchical in _items (and eg. _items(0)._items)
final NSArray array = (NSArray) (PropertyListParser.parse(processInputStream));
final NSDictionary dict = (NSDictionary) array.objectAtIndex(0);
final NSArray itemsArray = (NSArray) dict.get(SpUSBDataTypeIdentifiers.ITEMS);
return recurseUSBDevices(itemsArray);
}
public static List<MountedDevice> recurseUSBDevices(NSArray items)
{
final Builder<MountedDevice> builder = ImmutableList.builder();
for (NSObject item : items.getArray())
{
builder.addAll(recurseUSBDevice((NSDictionary) item));
}
return builder.build();
}
private static List<MountedDevice> recurseUSBDevice(final NSDictionary dict)
{
final Builder<MountedDevice> builder = ImmutableList.builder();
for (final Map.Entry<String, NSObject> entry : dict.entrySet())
{
if (entry.getKey().equals(SpUSBDataTypeIdentifiers.ITEMS))
{
// The USB device is a hub
builder.addAll(recurseUSBDevices((NSArray) entry.getValue()));
}
if (entry.getKey().equals(SpUSBDataTypeIdentifiers.VOLUMES))
{
// This is a mountable device. We need to get the volumes, and for each volume, return it.
List<MountedDevice> mountedDeviceOpt = parseVolumes((NSArray) (entry.getValue()));
for (MountedDevice mountedDevice : mountedDeviceOpt)
{
mountedDevice.setVendorId(((NSString) dict.get(SpUSBDataTypeIdentifiers.VENDOR_ID)).toString());
builder.add(mountedDevice);
}
}
}
return builder.build();
}
private static List<MountedDevice> parseVolumes(final NSArray nsArray)
{
final Builder<MountedDevice> builder = ImmutableList.builder();
for (final NSObject item : nsArray.getArray())
{
builder.add(parseVolume((NSDictionary) item));
}
return builder.build();
}
private static MountedDevice parseVolume(final NSDictionary item)
{
final String mountPoint = ((NSString) item.get(SpUSBDataTypeIdentifiers.MOUNT_POINT)).toString();
final String name = ((NSString) item.get(SpUSBDataTypeIdentifiers.NAME)).toString();
return new MountedDevice(mountPoint, name, null, null, MountState.MOUNTED);
}
}

Resources